我正在尝试训练神经网络来进行一些图像处理。我成功地使用了Synaptic.js,但是当我必须使用更多图层时,它学得非常慢。 Tensorflow.js样本描述了一些特定的案例,很难理解它们并适用于我的案例。有人可以帮我将这个Synaptic.js代码转换成Tensorflow.js吗?输入是RGB像素[0..1]的3x3(或更多)内核,输出是单个RGB像素[0..1]
const layers = [27, 9, 3];
const learningRate = 0.05;
const perceptron = new Synaptic.Architect.Perceptron(layers);
// Train
sampleData.forEach(([input, output]) => {
perceptron.activate(input);
perceptron.propagate(learningRate, output);
});
// Get result
const result = realData.map((input) => perceptron.activate(input));
答案 0 :(得分:1)
示例repo中有一些非常通用的TensorFlow.js示例: https://github.com/tensorflow/tfjs-examples
对于您的情况,您需要执行类似回购中的虹膜示例。
// Define the model.
const model = tf.sequential();
// you will need to provide the size of the individual inputs below
model.add(tf.layers.dense({units: 27, inputShape: INPUT_SHAPE}));
model.add(tf.layers.dense({units: 9});
model.add(tf.layers.dense({units: 3});
const optimizer = tf.train.adam(0.05);
modcel.compile({
optimizer: optimizer,
loss: 'categoricalCrossentropy',
metrics: ['accuracy'],
});
// Train.
const lossValues = [];
const accuracyValues = [];
// Call `model.fit` to train the model.
const history = await model.fit(input, output, {epochs: 10});
// Get result
const result = realData.map((input) => model.predict(input));