How to import python loss layer? (ImportError: No module named pyloss)

1,729 views
Skip to first unread message

Tanja

unread,
Jul 29, 2016, 5:04:16 AM7/29/16
to Caffe Users
Hello,

I try to create my own python loss layer.

But first, I wanted to test the implemented pyloss.py.
The file is still in folder caffe-masters/examples/pycaffe/layers.
I use this command to integrate the loss in my train_val.prototxt:

layer {
  type: 'Python'
  name: 'loss'
  top: 'loss'
  bottom: 'fc5_a'
  bottom: 'label'
  python_param {
    # the module name -- usually the filename -- that needs to be in $PYTHONPATH
    module: 'pyloss'
    # the layer name -- the class name in the module
    layer: 'EuclideanLossLayer'
  }
  # set loss weight so Caffe knows this is a loss layer.
  # since PythonLayer inherits directly from Layer, this isn't automatically
  # known to Caffe
  loss_weight: 1
}

But when I start the training using caffe - I get the error:
caffe ImportError: No module named pyloss

I followed the instructions of: http://chrischoy.github.io/research/caffe-python-layer/
and build Caffe with WITH_PYTHON_LAYER option, but nothing works.
I still have the defect note.

Do somebody know what I have to do, to import my python loss correctly in caffe?

FELIPE PETROSKI SUCH

unread,
Jul 29, 2016, 1:01:38 PM7/29/16
to Caffe Users
caffe ImportError: No module named pyloss
That means it couldn't find the file/module pyloss.py, that file has to be either in the same folder you are running caffe from (WORK DIR) or be in the python path. 

Zhao.Kai

unread,
Jul 31, 2016, 8:52:41 PM7/31/16
to Caffe Users
Make sure the pyloss.py is in the PYTHONPATH

Tanja

unread,
Aug 1, 2016, 6:35:29 AM8/1/16
to Caffe Users
But how do I check that?

Tanja

unread,
Aug 1, 2016, 6:52:21 AM8/1/16
to Caffe Users
Okay - I used :
export PYTHONPATH=/path/to/caffe/python:$PYTHONPATH
And that works!

Thank you!

Arghavan Arafati

unread,
Mar 28, 2017, 2:07:17 AM3/28/17
to Caffe Users
Hi,

Could you please let me know where did you copy your module? Since I've checked PYTHONPATH and I have my python layer in my PYTHONPATH but I still receive the error :

I0327 22:34:07.741192 29745 layer_factory.hpp:77] Creating layer data
ImportError: No module named segmentation_layers

Thanks in advance,

Best

Ara

yanru...@gmail.com

unread,
Apr 17, 2017, 11:04:12 AM4/17/17
to Caffe Users


在 2016年7月29日星期五 UTC+8下午5:04:16,Tanja写道:
Hello,
I also have this problem when use python layer
 
caffe ImportError: No module named pyloss

I build Caffe with WITH_PYTHON_LAYER option, and  have set the python layer. Have you solve it?

Mahfujur Rahman

unread,
Sep 7, 2017, 1:29:40 PM9/7/17
to Caffe Users
I tried but I got this unusual error.

F0908 13:28:49.386046  4552 layer_factory.hpp:69] Check failed: registry.count(type) == 0 (1 vs. 0) Layer type Log already registered.
*** Check failure stack trace: ***
    @     0x7f3a92a205cd  google::LogMessage::Fail()
    @     0x7f3a92a22433  google::LogMessage::SendToLog()
    @     0x7f3a92a2015b  google::LogMessage::Flush()
    @     0x7f3a92a22e1e  google::LogMessageFatal::~LogMessageFatal()
    @     0x7f3a4db91396  caffe::LayerRegistry<>::AddCreator()
    @     0x7f3a4db7407d  (unknown)
    @     0x7f3a93d606ba  (unknown)
    @     0x7f3a93d607cb  (unknown)
    @     0x7f3a93d658e2  (unknown)
    @     0x7f3a93d60564  (unknown)
    @     0x7f3a93d64da9  (unknown)
    @     0x7f3a813bcf09  (unknown)
    @     0x7f3a93d60564  (unknown)
    @     0x7f3a813bd571  (unknown)
    @     0x7f3a813bcfa1  dlopen
    @     0x7f3a9185388d  _PyImport_GetDynLoadFunc
    @     0x7f3a918c24be  _PyImport_LoadDynamicModule
    @     0x7f3a918c3300  (unknown)
    @     0x7f3a918c455a  PyImport_ImportModuleLevel
    @     0x7f3a9183b698  (unknown)
    @     0x7f3a918871e3  PyObject_Call
    @     0x7f3a9195d447  PyEval_CallObjectWithKeywords
    @     0x7f3a918305c6  PyEval_EvalFrameEx
    @     0x7f3a9195e01c  PyEval_EvalCodeEx
    @     0x7f3a9182cb89  PyEval_EvalCode
    @     0x7f3a918c11b4  PyImport_ExecCodeModuleEx
    @     0x7f3a918c1b8f  (unknown)
    @     0x7f3a918c3300  (unknown)
    @     0x7f3a918c455a  PyImport_ImportModuleLevel
    @     0x7f3a9183b698  (unknown)
    @     0x7f3a918871e3  PyObject_Call
    @     0x7f3a9195d447  PyEval_CallObjectWithKeywords
Reply all
Reply to author
Forward
0 new messages