I am writing my own little network, where I tried to implement the convolution with a kernel that detects edges
import * as tf from "@tensorflow/tfjs-node";
const model = tf.sequential()
// Layer 1: Convolutional
const kArr = [-1, 2, -1, -1, 2, -1, -1, 2, -1,]
const kernel = tf.tensor4d(kArr, [3, 3, 1, 1]).cast("float32").div(6)
model.add(
tf.layers.conv2d({
inputShape: [224, 224, 1],
filters: 1,
kernelSize: 3,
padding: "same",
activation: "relu",
weights: [kernel],
trainable: false
})
)
model.add(
tf.layers.conv2d({
inputShape: [224, 224, 1],
filters: 3,
kernelSize: 2,
padding: "same",
activation: "relu",
})
);
model.add(tf.layers.flatten())
model.add(tf.layers.dense({ units: 128, activation: "relu" }))
model.add(tf.layers.dense({ units: 64, activation: "relu" }))
model.add(tf.layers.dense({ units: 4, activation: "sigmoid" }))
model.compile({
optimizer: tf.train.adam(0.00001), //could be a parameter as well.
loss: tf.losses.meanSquaredError,
});
export { model as simpleModel };
I took the kernel from wikipedia Line detection - Wikipedia