Loading Inception-v1 model with weights trained using Caffe

72 views
Skip to first unread message

goutham....@gmail.com

unread,
Sep 12, 2017, 3:22:06 PM9/12/17
to BigDL User Group
Hi everyone,

I am trying to load the Weights of the Caffe model to the Incepetion model, but was facing a few errors, one of them is below :

py4j.Py4JException: Method loadCaffeModel([class com.intel.analytics.bigdl.nn.Sequential, class java.lang.String]) does not exist

In addition to the above error, I also have the below questions :

1. The link that I am referring for caffe model's weights is :  https://github.com/BVLC/caffe/tree/master/models/bvlc_googlenet. Is this right one ? if not please suggest the correct one.

2. I am referring to the documentation at : https://bigdl-project.github.io/0.2.0/#ProgrammingGuide/caffe-support/ ; to load caffe model's weights. But facing an error when using the last parameter 'match_all=True' ( I have tried with matchAll = True as well ). Can you please confirm if the documentation is right ?

I am using BigDL - 0.2.0 and python. Please find the 'InceptionV1 model' notebook that I am using and detailed error logs as attachment.


regards,
goutham.
Inception_v1.ipynb
error_log_2.txt
error_log_1.txt

Jennie Wang

unread,
Sep 12, 2017, 9:42:11 PM9/12/17
to BigDL User Group
There are two methods to load caffe model in python.

If you already create BigDL model, you need to call Model. load_caffe(model, defPath, modelPath, match_all=True, bigdl_type="float")

If you don't define BigDL model, you need to call Model.load_caffe_model(defPath, modelPath, bigdl_type="float").

So in your case, you need to use Model.load_caffe interface. The documentation is not correct in this case, created issue: https://github.com/intel-analytics/BigDL/issues/1552.

Thanks,
Jennie

goutham....@gmail.com

unread,
Sep 13, 2017, 1:52:12 AM9/13/17
to BigDL User Group
Thank you jenny for you reply. That worked.
Now, after loading the weights I am trying to predict the class of an image using this model. When I print the prediction output it does not show any class or index but this : "MapPartitionsRDD[22] at mapPartitions at PythonMLLibAPI.scala:1335 "

The code that I am using to preprocess the image before calling mode.predict_class is :
      input_img = 'cat.jpg'
      img = cv2.imread(input_img) # to read the data into numpy array 
      img_data_rdd = sc.parallelize(img)
      predict_result = model.predict_class(img_data_rdd)

Can you please let me know where I am doing wrong.

regards,
goutham  

Li, Zhichao

unread,
Sep 13, 2017, 2:05:06 AM9/13/17
to goutham....@gmail.com, BigDL User Group

You need to  predict_result.collect() as the returning result is a RDD.

 

Thanks,

Zhichao

--
You received this message because you are subscribed to the Google Groups "BigDL User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bigdl-user-gro...@googlegroups.com.
To post to this group, send email to bigdl-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bigdl-user-group/9dc62ddf-07d0-4927-8b3b-7cc08085ae73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

goutham....@gmail.com

unread,
Sep 13, 2017, 2:30:04 AM9/13/17
to BigDL User Group

Thanks for the quick reply. when I ran "predict_result.collect() " line i got  'Py4JJavaError' error.  Complete trace back of this error message can be found as attachment.
Can you please take a look at this ?

regards,
goutham.

To post to this group, send email to bigdl-u...@googlegroups.com.

py4java_error_log.txt

Jennie Wang

unread,
Sep 13, 2017, 2:34:02 AM9/13/17
to BigDL User Group
Also before you call model.predict_class, you need to preprocess the image and change to RDD[Sample]. You can reference this example (https://github.com/jenniew/BigDL/blob/imagenet/pyspark/dl/models/inception/inception.py)to preprocess image, and then call prediction.

Thanks,
Jennie

On Tuesday, September 12, 2017 at 11:05:06 PM UTC-7, Zhichao Li wrote:

To post to this group, send email to bigdl-u...@googlegroups.com.

goutham....@gmail.com

unread,
Sep 13, 2017, 11:58:18 AM9/13/17
to BigDL User Group
Hi Jenny,

For Transforming the pre-processed image to RDD[sample], I am trying to use  Sample.from_ndarray(image, label)'.
But since I am just trying to predict only a single unknown image, I am confused on what I have to pass for 'label' parameter.
Can you help me with this ?

I am pre-processing the image using below code:

input_img = 'cat.jpg'
img = cv2.imread(input_img) # to read the data into numpy array 
img_rows = 224
img_cols = 224
transform_input = Transformer([Crop(img_rows, img_cols, "center"), Flip(0.5), ChannelNormalizer(0.485, 0.456, 0.406, 0.229, 0.224, 0.225),
                                                TransposeToTensor(False)])
img_tranx = transform_input(img)
img_to_model = Sample.from_ndarray(img_tranx, ? )


regards,
goutham.

I tried to prep_process the input image using transformer function. 

Jennie Wang

unread,
Sep 13, 2017, 2:21:18 PM9/13/17
to BigDL User Group
You can set label as -1 or np.array(-1).

Thanks,
Jennie

goutham....@gmail.com

unread,
Sep 13, 2017, 2:40:03 PM9/13/17
to BigDL User Group
I tried that, but when I facing java error when trying to predict . I ran "model.predict_class(img_to_model)"  line for class prediction.
The error is :

Py4JError: An error occurred while calling o36.modelPredictClass. Trace:
py4j.Py4JException: Method modelPredictClass([class com.intel.analytics.bigdl.nn.Sequential, class com.intel.analytics.bigdl.python.api.Sample]) does not exist.

Please find the complete error log as attachment. It says' model predict class' is not present  in library. am I missing something ?

code I used :
input_img = 'cat.jpg'
img = cv2.imread(input_img) # to read the data into numpy array 
img_rows = 224
img_cols = 224
transform_input = Transformer([Crop(img_rows, img_cols, "center"), Flip(0.5), ChannelNormalizer(0.485, 0.456, 0.406, 0.229, 0.224, 0.225),
                                                TransposeToTensor(False)])
img_tranx = transform_input(img)
label = np.array(-1)
img_to_model = Sample.from_ndarray(img_tranx, label)
predict_result = model.predict_class(img_to_model)  # to predict

regards
goutham.


predict_class_error_log.txt

Jennie Wang

unread,
Sep 13, 2017, 8:05:23 PM9/13/17
to BigDL User Group
The img_to_model is only one Sample, please change to RDD[Sample] (i.e. sc.parallelize([img_to_model])) and then call model.predict_class

Thanks,
Jennie

Jason Dai

unread,
Sep 13, 2017, 9:04:43 PM9/13/17
to Jennie Wang, BigDL User Group
You may also refer to the BigDL tutorials (e.g., https://github.com/intel-analytics/BigDL-Tutorials/blob/master/notebooks/neural_networks/cnn.ipynb) for examples on using BigDL.

Thanks,
-Jason


To unsubscribe from this group and stop receiving emails from it, send an email to bigdl-user-group+unsubscribe@googlegroups.com.
To post to this group, send email to bigdl-user-group@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bigdl-user-group/272ffa94-1bde-4a83-abcf-9e97946c30f7%40googlegroups.com.

goutham....@gmail.com

unread,
Sep 14, 2017, 1:09:20 AM9/14/17
to BigDL User Group
Thanks a lot Jennie, That worked. 

regards,
goutham.

Dave Nielsen

unread,
Sep 14, 2017, 3:37:59 AM9/14/17
to BigDL User Group
Nice work Goutham. Thank you Jennie!!

Dave

Dave Nielsen
Technical Program Manager

BigDL - Deep Learning for Spark
Big Data Technologies, DPD, Intel Software

text: 415-531-6674

Reply all
Reply to author
Forward
0 new messages