[英]Convert Convnet.js neural network model to Keras Tensorflow
I have a neural network model that is created in convnet.js that I have to define using Keras.我有一个在 convnet.js 中创建的神经网络模型,我必须使用 Keras 定义它。 Does anyone have an idea how can I do that?
有谁知道我该怎么做?
neural = {
net : new convnetjs.Net(),
layer_defs : [
{type:'input', out_sx:4, out_sy:4, out_depth:1},
{type:'fc', num_neurons:25, activation:"regression"},
{type:'regression', num_neurons:5}
],
neuralDepth: 1
}
this is what I could do so far.这是我目前能做的。 I cannot ve sure if it's correct.
我不能确定它是否正确。
#---Build Model-----
model = models.Sequential()
# Input - Layer
model.add(layers.Dense(4, activation = "relu", input_shape=(4,)))
# Hidden - Layers
model.add(layers.Dense(25, activation = "relu"))
model.add(layers.Dense(5, activation = "relu"))
# Output- Layer
model.add(layers.Dense(1, activation = "linear"))
model.summary()
# Compile Model
model.compile(loss= "mean_squared_error" , optimizer="adam", metrics=["mean_squared_error"])
From the Convnet.js doc : "your last layer must be a loss layer ('softmax' or 'svm' for classification, or 'regression' for regression)."来自 Convnet.js 文档:“你的最后一层必须是一个损失层('softmax' 或 'svm' 用于分类,或 'regression' 用于回归)。” Also : "Create a regression layer which takes a list of targets (arbitrary numbers, not necessarily a single discrete class label as in softmax/svm) and backprops the L2 Loss."
另外:“创建一个回归层,它采用目标列表(任意数字,不一定是 softmax/svm 中的单个离散类标签)并反向传播 L2 损失。”
It's unclear.不清楚。 I suspect "regression" layer is just another layer of Dense (Fully connected) neurons.
我怀疑“回归”层只是另一层密集(全连接)神经元。 The 'regression' word probably refers to linear activity.
“回归”一词可能指的是线性活动。 So, no 'relu' this time ?
那么,这次没有'relu'吗?
Anyway, it would probably look something like (no sequential mode):无论如何,它可能看起来像(无顺序模式):
from keras.layers import Dense
from keras.models import Model
my_input = Input(shape = (4, ))
x = Dense(25, activation='relu')(x)
x = Dense(4)(x)
my_model = Model(input=my_input, output=x, loss='mse', metrics='mse')
my_model.compile(optimizer=Adam(LEARNING_RATE), loss='binary_crossentropy', metrics=['mse'])
After reading a bit of the docs, the convnet.js seems like a nice project.阅读了一些文档后,convnet.js 似乎是一个不错的项目。 It would be much better with somebody with neural network knowledge on board.
有神经网络知识的人会更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.