首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通用Tensorflow.js训练示例

通用Tensorflow.js训练示例
EN

Stack Overflow用户
提问于 2018-04-20 17:00:23
回答 1查看 631关注 0票数 0

我试着训练神经网络来做一些图像处理。我在Synaptic.js中成功地做到了这一点,但是当我不得不使用更多的层时,它学习得非常慢。Tensorflow.js示例描述了一些具体的情况,很难理解它们并应用到我的案例中。有人能帮我把这个Synaptic.js代码转换成Tensorflow.js吗?输入是RGB像素0..1的3x3 (或更多)内核,输出是单个RGB像素0..1

代码语言:javascript
复制
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));
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-20 18:48:21

在repo: TensorFlow.js示例中有一些非常通用的https://github.com/tensorflow/tfjs-examples示例。

对于你的情况,你将需要做一些类似虹膜的例子在回购。

代码语言:javascript
复制
// 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));
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49946525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档