how to run caffemodel file

117 views
Skip to first unread message

S.M

unread,
Jun 27, 2020, 9:53:47 PM6/27/20
to Caffe Users
Hi ! I am a bit confused on how to get the .caffemodel file to run. I'm looking to use the trained dataset and apply portrait images to get the segmented results. Kindly advise.

Tamas Nemes

unread,
Jun 28, 2020, 2:31:24 PM6/28/20
to Caffe Users
This largely depends on which programming language you want to use. Can you please tell us? Then we probably can provide links to example scripts.

S.M

unread,
Jun 30, 2020, 9:09:09 AM6/30/20
to Caffe Users
Hi there!

I will be using python! Thank you for the help!

Tamas Nemes

unread,
Jun 30, 2020, 10:18:54 AM6/30/20
to Caffe Users
So this would be a good starting point I guess:


As you can see, this is a fairly simple program with which you can load your pre-trained model, do some image transformations and directly pass the image data to the network for processing. All you need is .prototxt, .caffemodel and .binaryproto files. As you chose to work on caffe, I assume you have a Linux-based system, on which this program should work fine. If you want to use your GPU, you can set it by changing mode to set_mode_gpu().
However, you must have Caffe for Python installed. Have you managed to install it yet? If not, I suggest following guide:


It's best here to use Caffe with the newest OpenCV version, optionally built with CUDA support.
If you encounter any problems, please let us know! 

S.M

unread,
Jun 30, 2020, 10:23:04 AM6/30/20
to Caffe Users
Hi there!

Thank you for the resources. I will look through them and get back to you with questions.

I actually use a MAC OS system. Will that be alright? I came across this .caffemodel file as I was looking for pre-trained models as described in (https://github.com/shelhamer/fcn.berkeleyvision.org) this paper: 

Fully Convolutional Models for Semantic Segmentation
Evan Shelhamer*, Jonathan Long*, Trevor Darrell
PAMI 2016
arXiv:1605.06211

Tamas Nemes

unread,
Jun 30, 2020, 10:30:25 AM6/30/20
to Caffe Users
Well, I guess then you will probably came across slightly more errors during installation, but you can check out some guides like this:


Or you can simply search for "install caffe on os x"
And just the .caffemodel is not enough for running a network. You also need a .prototxt configuration file and a .binaryproto data file. Try searching for those on free sources like GitHub.

S.M

unread,
Jul 6, 2020, 10:49:55 AM7/6/20
to Caffe Users
Hi there.

I tried installing caffe using the link you have provided but I was facing some issues with the 'make all' step :https://medium.com/@shardulgo/installing-caffe-1-0-on-mac-os-x-part-1-4-64cf479be75d

src/caffe/data_transformer.cpp:2:10: fatal error: 'opencv2/core/core.hpp' file not found

i think it's because it can't find the opencv (version 4.5) ?

I scrapped this attempt and tried to follow this: https://medium.com/@buffaloal/build-caffe-with-anaconda-on-macos-1070a8d0a9fe
But I am currently stuck at running the CMake Step 3 as I am getting this error when I run "cmake .." : 

CMake Error: The source directory ".<directory>.." does not appear to contain CMakeLists.txt.


Kindly advise.

Tamas Nemes

unread,
Jul 7, 2020, 3:09:42 PM7/7/20
to Caffe Users
In my opinion, it's no use to scrap attempts completely until you really mess the install up or can confirm that there is some unsolvable error which, this time, is not the case. Although I can't say anything for sure because I never worked on MacOS, the error states that the program does not find your OpenCV installation.
I advise you to look for the folder "opencv2" in your computer (using the search function). For me on Ubuntu, this path is "/usr/local/include/opencv4". Then add this path to your INCLUDE_DIRS in Makefile.config. Make sure that before you make a new build attempt, you clear your build files first using make clean. Then it should be able to find it. I would have also recommended to use package config, but I don't think it exists on Mac.

S.M

unread,
Jul 10, 2020, 12:11:09 PM7/10/20
to Caffe Users
Hi there! 

Thank you for your help. I have successfully added caffe and ran the instructions till completion, whilst getting some errors in the way which I resolved.


I want to ask how will my code be structured because it currently fails at caffe.Net as "module 'caffe' has no attribute 'Net'".

dir running_caffe
 - caffe (git clone dir)
 - prediction.py

Thank you once again! :)

S.M

unread,
Jul 10, 2020, 11:01:54 PM7/10/20
to Caffe Users
Hi there!

Nvm, I have figured out my mistake -- tried make pycaffe with Python 2.7 and it works!

Now, I am trying to follow https://gist.github.com/dersmon/8b701a41a3a1d6b45098 to run https://github.com/shelhamer/fcn.berkeleyvision.org/tree/master/voc-fcn8s . Is there any tutorial for running FCN via Caffe?

Thanks in advance.

S.M

unread,
Jul 10, 2020, 11:13:35 PM7/10/20
to Caffe Users
Hi again!


If I want to use my own images, can I just replace the demo/image.jpg with mine?

S.M

unread,
Jul 15, 2020, 11:03:53 PM7/15/20
to Caffe Users
Hi there! 

Please advise accordingly. I will really appreciate your feedback. :)

Tamas Nemes

unread,
Jul 16, 2020, 9:59:55 AM7/16/20
to Caffe Users
Making Caffe with Python 2 is generally not a good idea. Since it's outdated, you are much more likely to run into errors. I would rather consider it a quick workaround instead of a solution.
There is very little tutorial for what you provided, but theoritically, it should be possible. Take a look at this:


This is the training script for MobileNet SSD. As you see, you provide the solver.prototxt (https://github.com/shelhamer/fcn.berkeleyvision.org/blob/master/voc-fcn8s/solver.prototxt) and pre-trained weights if you wish. 
You can certainly switch out the example images to your own, this is the purpose of example images. Running the inference program by dersmon should not be a good idea here; instead, use the one that is included with FCN. You need to provide your deploy.prototxt and the .caffemodel-file (which can be downloaded using https://github.com/shelhamer/fcn.berkeleyvision.org/blob/master/voc-fcn8s/caffemodel-url) and hopefully, you'll be able to do proper inference. The details are up to you to figure out.

S.M

unread,
Jul 16, 2020, 10:12:48 AM7/16/20
to Caffe Users
Thank you, I will surely take a look. 

I used Python 2 as I was facing some issues with the make pycaffe not being able to find the correct python3 version. With research I found that Python2 was a more working solution.

I will try out your examples with the current Python2 environment I have created.
Reply all
Reply to author
Forward
0 new messages