-
Notifications
You must be signed in to change notification settings - Fork 965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error in conversion of Inception Model from Keras to CNTK #19
Comments
Hi @coolrishi2005 , The input layer of keras InceptionV3 doesn't contain shapes info, which is placed in model config batch_input_shape. So it can't be parsed correctly. To fix it, please change the code BackEndModel = applications.InceptionV3(include_top=False, weights='imagenet') to BackEndModel = applications.InceptionV3(input_shape=(299, 299, 3), include_top=False, weights='imagenet') And I tested it with follow scripts $ python -m mmdnn.conversion._script.convertToIR -f keras -d ./kit_imagenet -n incpetionTopModel.json -w incpetionTopModel.h5
$ python -m mmdnn.conversion._script.IRToCode --dstModelFormat cntk --IRModelPath kit_imagenet.pb --dstModelPath kit_imagenet.py --IRWeightPath kit_imagenet.npy
$ python -m mmdnn.conversion.examples.cntk.imagenet_test -n kit_imagenet.py -w kit_imagenet.npy --dump cntkmodel.dnn
CNTK model file is saved as [cntkmodel.dnn], generated by [kit_imagenet.py] and [kit_imagenet.npy]. Hope it can help you. |
Hi kitstar, Thanks for the help. The model has been converted to *.dnn, but with the following warning: (C:\Program Files\Anaconda3\envs\py35) D:\mmdnn\conversion\cntk>python -m mmdnn.conversion.examples.cntk.imagenet_test Is it fine? |
Supposed to be fine. |
Great!! Thanks. |
Hi kitstar, I have saved the created and saved the Inception model with following parameters: I am trying to load the above saved model (cntkInceptionTopModel.dnn) using cntk CPP Evaluation Example provided by Microsoft (/~https://github.com/Microsoft/CNTK/blob/release/2.3/Examples/Evaluation/CNTKLibraryCPPEvalCPUOnlyExamples/CNTKLibraryCPPEvalCPUOnlyExamples.cpp) Now, for evaluation, I am providing binary RGB data as input (which is of size 150x150x3, i.e. 67500 bytes data). Following is the code for the same: void EvaluationSingleSampleUsingDense(const wchar_t* modelFile, const DeviceDescriptor& device)
} But, during the call of modelFunc->Evaluate(inputDataMap, outputDataMap, device), I am getting following runtime error: Can you please help? |
Hi, |
Hey, no issue. I am working on it. |
Hi kitstar,
I have saved Inception Model and its Weights using the below code:
import numpy as np
import tensorflow as tf
import os
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Dropout, Flatten, Dense
from keras import applications
BackEndModel = applications.InceptionV3(include_top=False, weights='imagenet')
model_json = BackEndModel.to_json()
with open("incpetionTopModel.json", "w") as json_file:
json_file.write(model_json)
BackEndModel.save_weights("incpetionTopModel.h5")
Now, I want to convert this model and weight files to cntk. Using the standard procedure as mentioned in mmdnn documentation, I am getting the following error in the last step (After generating the CNTK code snippet, you can convert the code and IR weights file to CNTK original model). Following is the error trace:
(C:\Program Files\Anaconda3\envs\py35) >python -m mmdnn.conversion.examples.cntk.imagenet_test
-n cntkInceptionTopModel.py -w IRIncpetionTopModel.npy --dump cntkInceptionTopMo
del.dnn
Selected CPU as the process wide default device.
C:\Program Files\Anaconda3\envs\py35\lib\site-packages\cntk\core.py:82: RuntimeW
arning: data is not C contiguous; rearrange your data/computation to avoid costl
y data conversions
RuntimeWarning)
Traceback (most recent call last):
File "C:\Program Files\Anaconda3\envs\py35\lib\runpy.py", line 184, in _run_mo
dule_as_main
"main", mod_spec)
File "C:\Program Files\Anaconda3\envs\py35\lib\runpy.py", line 85, in run_cod
e
exec(code, run_globals)
File "C:\Program Files\Anaconda3\envs\py35\lib\site-packages\mmdnn\conversion
examples\cntk\imagenet_test.py", line 57, in
tester = TestCNTK()
File "C:\Program Files\Anaconda3\envs\py35\lib\site-packages\mmdnn\conversion
examples\cntk\imagenet_test.py", line 22, in init
self.model = self.MainModel.KitModel(self.args.w)
File "D:\Rishi\Machine Learning\CNTK\MMdnn-master\mmdnn\conversion\cntk\cntkIn
ceptionTopModel.py", line 27, in KitModel
conv2d_189 = convolution(input_3, strides = (2, 2,), auto_padding = [Fa
lse, False, False], name = 'conv2d_189')
File "D:\Rishi\Machine Learning\CNTK\MMdnn-master\mmdnn\conversion\cntk\cntkIn
ceptionTopModel.py", line 374, in convolution
input = cntk.transpose(input, [dim - 2] + list(range(0, dim - 2)))
File "C:\Program Files\Anaconda3\envs\py35\lib\site-packages\cntk\internal\swi
g_helper.py", line 69, in wrapper
result = f(*args, **kwds)
File "C:\Program Files\Anaconda3\envs\py35\lib\site-packages\cntk\ops_init
.py", line 2056, in transpose
return transpose(x, perm, name)
RuntimeError: invalid vector subscript
Kindly help me out with it.
I have already added -node add as suggested by you while generating IRCode from Keras Model.
The text was updated successfully, but these errors were encountered: