Repository navigation
Description
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.
Activity
kitstar commentedon Dec 5, 2017
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
to
And I tested it with follow scripts
Hope it can help you.
coolrishi2005 commentedon Dec 6, 2017
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
-n cntkInceptionTopModel.py -w IRInceptionTopModel.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)
CNTK model file is saved as [cntkInceptionTopModel.dnn], generated by [cntkIncep
tionTopModel.py] and [IRInceptionTopModel.npy].
Is it fine?
kitstar commentedon Dec 6, 2017
Supposed to be fine.
coolrishi2005 commentedon Dec 6, 2017
Great!! Thanks.
coolrishi2005 commentedon Dec 6, 2017
Hi kitstar,
I have saved the created and saved the Inception model with following parameters:
BackEndModel = applications.InceptionV3(input_shape=(150, 150, 3), include_top=False, weights='imagenet')
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)
{
printf("\n===== Evaluate single sample using dense format.\n");
}
But, during the call of modelFunc->Evaluate(inputDataMap, outputDataMap, device), I am getting following runtime error:
Unhandled exception at 0x00007FFE1527FEDE (Cntk.Core-2.3d.dll) in CNTKLibraryCPPEvalCPUOnlyExamples.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x000000474F603FD0). occurred
Can you please help?
kitstar commentedon Dec 6, 2017
Hi,
Does the converted model with original input shape (299, 299, 3) work?
If it works, maybe resizing your image in your application is a workaround.
coolrishi2005 commentedon Dec 6, 2017
Hey, no issue. I am working on it.
Thanks :)