It would be great if this is python 3.5 compatible
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]toc_i = int(input.get_shape()[-1]) - line 207:
input_shape = map(lambda v: v.value, input.get_shape())toinput_shape = list(map(lambda v: v.value, input.get_shape()))
and then for basestring (line78) there are two options:
- add
from past.builtins import basestringas import (from the future package) - or change
if isinstance(fed_layer, basestring):toif isinstance(fed_layer, str):(I think this should work as well)
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:
- data_dict = np.load(data_path).item() changed to data_dict = np.load(data_path, encoding='latin1').item()
- 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.
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