Custom binary classification model using openvino on ncs2

Custom binary classification model using openvino on ncs2


Hello, hope you doing good.

I'm running a custom 2 layer CNN classification model on images on Openvino target using ncs2. My results are always class id ="0" irrespective of all the images. The model is giving expected results in the backend(when i load the h5 file and predict), whereas it fails while i do it on inference samples called "classification sample". Hope you can help me out.

Here is the model structure

model = Sequential()
    model.add(Conv2D(4, (3, 3), strides=(2, 2), input_shape=(img_width, img_width,1), padding='valid'))
    model.add(BatchNormalization())
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(2, 2)))
    
    model.add(Conv2D(1, (3, 3),padding='valid'))
    #model.add(BatchNormalization())
    model.add(Activation('relu'))
    #model.add(MaxPooling2D(pool_size=(2, 2)))
    #model.add(GlobalMaxPooling2D())

    model.add(Flatten())  # this converts our 3D feature maps to 1D feature vectors
    
    #model.add(GlobalMaxPooling2D())
    model.add(Dense(1))
    model.add(Activation('sigmoid'))

The openvino version im using is 2019.1.144

The model optimizer command is

python3 mo.py --input_model 'weights/2layer_tyqi.pb' --output_dir /ir_files --input_shape [1,100,100,1] --data_type FP16

Here is the h5 file containing the model, and pb file and the script i used to convert from h5 to pb in the attatchment.

running this same model on mnist dataset with last layer modeified to 10 classes works. Any idea about that?

I suspect that binary classification needs some special configuration to be done. Is it something like that. My dataset consists of two classes and sigmoid layer at the end. Please provide your opinion on this. Any help is appreciated. 

Thank you!

AttachmentSize
Downloadapplication/zip files.zip14.35 KB
7 posts / 0 new

Hi kalaiselvan,

Thank you for reaching out.
It seems you have an older Openvino™ toolkit version, please try to run your commands again using the latest version and tell us if the results persist.  
Also, if you trained your model with images in RGB channel order, you need to use the flag --reverse_input_channels when converting the model to IR. This is because the OpenVINO samples load the images in the BGR channel order.  
 
Please give this a try, let us know if you have additional questions. 

Regards,

Randall B.


Hi, i have tried the following approaches you mentioned and still the results persist. Im getting class id as always 0 in my custom binary classification model trained on my custom dataset. where as im able to get accurate results for the same model trained on mnist dataset.

And i would like to add a point. Reversing input channels can be applied only if number of channels in my input is 3 right?. My input is a single channel image.

Can you have a look at it and help me out if possible.

Thank you!

 


Hi kalaiselvan,

Are you using our classification sample, right? Can you provide the command you are using to run the sample?

Please check this when to reverse input Channels.

Regards,

Randall B.


python3 mo.py --input_model 'models/acrylic_white_model.pb' --output_dir /models/ir_files/FP_16 -b 1 --reverse_input_channels --data_type FP16
 

Here is the command i use to generate the ir file using model optimizer. And i checked the link you provided. Seems like i did the same. Still doesnt make any difference in my result.


Hi i am still waiting for the clarification. As i have tried revsersing input channels and still it predicts all samples as a single class. As i dont see any problem in the model or in the conversion process. Since the same model is working on mnist dataset. Any idea what might be the problem here?

Seems like some problem in handling the input during inference part. Kindly respond.


Hi kalaiselvan, 

Using the classification sample application we are unable to run the converted model. 

Did you modify the sample application code? If so, could you share the file, the command used to run the sample application, and also a couple of sample images you are using for us to test? 

Regards, 

Randall B. 

Leave a Comment

Please sign in to add a comment. Not a member? Join today