Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Community Manager
311 Views

Failing to run a very simple Keras example

Hi,

 

I'm moving the first steps in deep learning with Movidius stick, and I'm stuck in this very simple problem..

 

I have this very simple code in Keras:

 

import numpy as np

 

np.random.seed(123) # for reproducibility

 

from keras.models import Sequential

 

from keras.layers import Dense, Dropout, Activation, Flatten

 

from keras.layers import Convolution2D, MaxPooling2D

 

from keras.utils import np_utils

 

from keras.datasets import mnist

 

4. Load pre-shuffled MNIST data into train and test sets

 

(X_train, y_train), (X_test, y_test) = mnist.load_data()

 

5. Preprocess input data

 

X_train = X_train.reshape(X_train.shape[0], 28, 28, 1)

 

X_test = X_test.reshape(X_test.shape[0], 28, 28, 1)

 

X_train = X_train.astype('float32')

 

X_test = X_test.astype('float32')

 

X_train /= 255

 

X_test /= 255

 

6. Preprocess class labels

 

Y_train = np_utils.to_categorical(y_train, 10)

 

Y_test = np_utils.to_categorical(y_test, 10)

 

7. Define model architecture

 

model = Sequential()

 

model.add(Convolution2D(32, 3, 3, activation='relu', input_shape=(28,28,1), name="input"))

 

model.add(Convolution2D(32, 3, 3, activation='relu'))

 

model.add(MaxPooling2D(pool_size=(2,2)))

 

model.add(Dropout(0.25))

 

model.add(Flatten())

 

model.add(Dense(128, activation='relu'))

 

model.add(Dropout(0.5))

 

model.add(Dense(10, activation='softmax', name="output"))

 

8. Compile model

 

model.compile(loss='categorical_crossentropy',

 

optimizer='adam',

 

metrics=['accuracy'])

 

9. Fit model on training data

 

model.fit(X_train, Y_train,

 

batch_size=32, epochs=1, verbose=1)

 

10. Evaluate model on test data

 

score = model.evaluate(X_test, Y_test, verbose=0)

 

model_json = model.to_json()

 

with open("model.json", "w") as json_file:

 

json_file.write(model_json)

 

model.save_weights("model.h5")

 

I'm trying to generate a graph file using this tool: https://github.com/ardamavi/Intel-Movidius-NCS-Keras

 

But when it run mvNCCompile I get this error: KeyError: "The name 'input:0' refers to a Tensor which does not exist. The operation, 'input', does not exist in the graph."

 

Can you help me?

 

Thank you

Tags (2)
0 Kudos
1 Reply
Highlighted
Community Manager
15 Views

Sorry for my ignorance, I solved.. I just turned the model into functional keras mode and removed Dropouts layers.

0 Kudos