简体   繁体   中英

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. 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)." 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."

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 ?

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. It would be much better with somebody with neural network knowledge on board.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM