Normalise the input data
This commit is contained in:
parent
00075b1823
commit
926a82bebf
2 changed files with 11 additions and 7 deletions
|
@ -30,10 +30,14 @@ class DataPreprocessor {
|
|||
|
||||
let filenames = await fs.promises.readdir(dirpath);
|
||||
for(let filename of filenames) {
|
||||
let imagetensor = tf.node.decodeImage(
|
||||
await fs.promises.readFile(path.join(dirpath, filename)),
|
||||
let imagebin = await fs.promises.readFile(path.join(dirpath, filename));
|
||||
let imagetensor = tf.tidy(() => {
|
||||
// Normalise the data to be 0 - 1
|
||||
return tf.node.decodeImage(
|
||||
imagebin,
|
||||
3 // channels
|
||||
);
|
||||
).cast("float32").div(255);
|
||||
});
|
||||
if(imagetensor.shape[0] == 256
|
||||
&& imagetensor.shape[1] == 256
|
||||
&& imagetensor.shape[0] == 3)
|
||||
|
|
|
@ -13,7 +13,7 @@ export default function(cats_count, image_size, use_crossentropy = false) {
|
|||
kernelSize: 5,
|
||||
filters: 3,
|
||||
strides: 1,
|
||||
activation: "relu"
|
||||
activation: "tanh"
|
||||
}));
|
||||
if(image_size > 32) {
|
||||
model.add(tf.layers.conv2d({
|
||||
|
@ -22,7 +22,7 @@ export default function(cats_count, image_size, use_crossentropy = false) {
|
|||
kernelSize: 5,
|
||||
filters: 3,
|
||||
strides: 2,
|
||||
activation: "relu"
|
||||
activation: "tanh"
|
||||
}));
|
||||
model.add(tf.layers.conv2d({
|
||||
name: "conv2d_3",
|
||||
|
@ -30,7 +30,7 @@ export default function(cats_count, image_size, use_crossentropy = false) {
|
|||
kernelSize: 5,
|
||||
filters: 3,
|
||||
strides: 2,
|
||||
activation: "relu"
|
||||
activation: "tanh"
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue