Pietro
Pietro

Reputation: 13164

Error converting a model from Caffe to Tensorflow

ImportError: No module named kaffe.tensorflow

Trying to convert a model from Caffe to Tensorflow with the caffe-tensorflow converter.

With this command:

convert.py --caffemodel ./VGG_ILSVRC_19_layers.caffemodel --data-output-path ./TF_conv/dataOutput.npz --code-output-path ./TF_conv/codeOutput.py ./VGG_ILSVRC_19_layers_deploy.prototxt

I get this code output file:

from kaffe.tensorflow import Network

class VGG_ILSVRC_19_layers(Network):
    def setup(self):
        (self.feed('data')
             .conv(3, 3, 64, 1, 1, name='conv1_1')
             .conv(3, 3, 64, 1, 1, name='conv1_2')
             .max_pool(2, 2, 2, 2, name='pool1')
             .conv(3, 3, 128, 1, 1, name='conv2_1')
             .conv(3, 3, 128, 1, 1, name='conv2_2')
             .max_pool(2, 2, 2, 2, name='pool2')
             .conv(3, 3, 256, 1, 1, name='conv3_1')
             .conv(3, 3, 256, 1, 1, name='conv3_2')
             .conv(3, 3, 256, 1, 1, name='conv3_3')
             .conv(3, 3, 256, 1, 1, name='conv3_4')
             .max_pool(2, 2, 2, 2, name='pool3')
             .conv(3, 3, 512, 1, 1, name='conv4_1')
             .conv(3, 3, 512, 1, 1, name='conv4_2')
             .conv(3, 3, 512, 1, 1, name='conv4_3')
             .conv(3, 3, 512, 1, 1, name='conv4_4')
             .max_pool(2, 2, 2, 2, name='pool4')
             .conv(3, 3, 512, 1, 1, name='conv5_1')
             .conv(3, 3, 512, 1, 1, name='conv5_2')
             .conv(3, 3, 512, 1, 1, name='conv5_3')
             .conv(3, 3, 512, 1, 1, name='conv5_4')
             .max_pool(2, 2, 2, 2, name='pool5')
             .fc(4096, name='fc6')
             .fc(4096, name='fc7')
             .fc(1000, relu=False, name='fc8')
             .softmax(name='prob'))

With: python ./codeOutput.py I get this error:

Traceback (most recent call last):
  File "./codeOutput.py", line 1, in <module>
    from kaffe.tensorflow import Network
ImportError: No module named kaffe.tensorflow

Do I have to put the codeOutput.py file in the directory where the kaffe.tensorflow module is?
Do I have to copy the kaffe.tensorflow module where my file is?
Can I connect the two in some way?

Upvotes: 0

Views: 1821

Answers (1)

Maurice Frank
Maurice Frank

Reputation: 86

caffe-tensorflow has to be inside your PYTHONPATH so python can find the modules. You can either edit the PYTHONPATH enviroment variable inside your .bashrc. For example:

export PYTHONPATH='/path/to/caffe-tensorflow'

or you add the path inside your script:

import sys
sys.path.insert(0, '/path/to/caffe-tensorflow')

Upvotes: 1

Related Questions