caffe-tensorflow icon indicating copy to clipboard operation
caffe-tensorflow copied to clipboard

It would be great if this is python 3.5 compatible

Open zhongzyd opened this issue 9 years ago • 3 comments

zhongzyd avatar Aug 19 '16 06:08 zhongzyd

If it's just the case of using the converted model in python 3 it's not so hard to adapt. There are just a few steps you have to do:

First: There are some problems of loading numpy files from python2 into python3. I figured out that using the pickle library works better. So basically: convert your model + weights, save your weights as pickle (not .npy) in python2. Load them with pickle.load in python3 and then save the dict with numpy (in python3) as weights.npy.

Second: There are just a few lines of code (in the network.py) you have to adapt, so that the created model.py and network.py can be used under python3. I'm not sure if I remember all of them, but some are:

  • line 120: c_i = input.get_shape()[-1] to c_i = int(input.get_shape()[-1])
  • line 207: input_shape = map(lambda v: v.value, input.get_shape()) to input_shape = list(map(lambda v: v.value, input.get_shape()))

and then for basestring (line78) there are two options:

  • add from past.builtins import basestring as import (from the future package)
  • or change if isinstance(fed_layer, basestring): to if isinstance(fed_layer, str): (I think this should work as well)

kratzert avatar Feb 09 '17 15:02 kratzert

I find a way to directly use the converted model in Python 3.5 (with TF 1.0.0), instead of using pickle to convert npy file first. Basically the load() function in class Network() in network.py needs to be modified at two lines:

  1. data_dict = np.load(data_path).item() changed to data_dict = np.load(data_path, encoding='latin1').item()
  2. for param_name, data in data_dict[op_name].iteritems(): changed to for param_name, data in data_dict[op_name].items():

And as @kratzert mentions, these three parts in network.py need to be handled too: line 120, line 207 and the basestring issue.

However, I do hope they could provide a Python 3.x-compatible version to convert the models.

NoNamesLeft4Me avatar Mar 10 '17 22:03 NoNamesLeft4Me

If you have such a problem using different Python versions or using Windows consider running it with Docker:

https://github.com/nicolov/segmentation_keras/tree/master/conversion https://github.com/ivanzhovannik/convert_caffe_windows

ivanzhovannik avatar Feb 08 '18 18:02 ivanzhovannik