Normalise the input data

This commit is contained in:
Starbeamrainbowlabs 2020-12-15 18:40:01 +00:00
parent 00075b1823
commit 926a82bebf
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 11 additions and 7 deletions

View file

@ -30,10 +30,14 @@ class DataPreprocessor {
let filenames = await fs.promises.readdir(dirpath); let filenames = await fs.promises.readdir(dirpath);
for(let filename of filenames) { for(let filename of filenames) {
let imagetensor = tf.node.decodeImage( let imagebin = await fs.promises.readFile(path.join(dirpath, filename));
await fs.promises.readFile(path.join(dirpath, filename)), let imagetensor = tf.tidy(() => {
3 // channels // Normalise the data to be 0 - 1
); return tf.node.decodeImage(
imagebin,
3 // channels
).cast("float32").div(255);
});
if(imagetensor.shape[0] == 256 if(imagetensor.shape[0] == 256
&& imagetensor.shape[1] == 256 && imagetensor.shape[1] == 256
&& imagetensor.shape[0] == 3) && imagetensor.shape[0] == 3)

View file

@ -13,7 +13,7 @@ export default function(cats_count, image_size, use_crossentropy = false) {
kernelSize: 5, kernelSize: 5,
filters: 3, filters: 3,
strides: 1, strides: 1,
activation: "relu" activation: "tanh"
})); }));
if(image_size > 32) { if(image_size > 32) {
model.add(tf.layers.conv2d({ model.add(tf.layers.conv2d({
@ -22,7 +22,7 @@ export default function(cats_count, image_size, use_crossentropy = false) {
kernelSize: 5, kernelSize: 5,
filters: 3, filters: 3,
strides: 2, strides: 2,
activation: "relu" activation: "tanh"
})); }));
model.add(tf.layers.conv2d({ model.add(tf.layers.conv2d({
name: "conv2d_3", name: "conv2d_3",
@ -30,7 +30,7 @@ export default function(cats_count, image_size, use_crossentropy = false) {
kernelSize: 5, kernelSize: 5,
filters: 3, filters: 3,
strides: 2, strides: 2,
activation: "relu" activation: "tanh"
})); }));
} }