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

text.split error

Open SeungHwa92 opened this issue 7 years ago • 8 comments

When I run convert.py, I got some trouble which is following

File "C:/Caffe/caffe/python/caffe2tensorflow/convert.py", line 61, in convert('minc-model/deploy-vgg16.prototxt','minc-model/minc-vgg16.caffemodel','mydata.py','mycode.py','train') File "C:/Caffe/caffe/python/caffe2tensorflow/convert.py", line 28, in convert transformer = TensorFlowTransformer(def_path, caffemodel_path, phase=phase) File "C:\Caffe\caffe\python\caffe2tensorflow\kaffe\tensorflow\transformer.py", line 221, in init self.load(def_path, data_path, phase) File "C:\Caffe\caffe\python\caffe2tensorflow\kaffe\tensorflow\transformer.py", line 227, in load graph = GraphBuilder(def_path, phase).build() File "C:\Caffe\caffe\python\caffe2tensorflow\kaffe\graph.py", line 140, in init self.load() File "C:\Caffe\caffe\python\caffe2tensorflow\kaffe\graph.py", line 146, in load text_format.Merge(def_file.read(), self.params) File "C:\Users\User\Anaconda3\lib\site-packages\google\protobuf\text_format.py", line 474, in Merge text.split('\n'), TypeError: a bytes-like object is required, not 'str'

To solve this trouble, I change : text.split('\n') -> text.split('\n'.encode()) but also have some trouble

File "C:\Users\User\Anaconda3\lib\site-packages\google\protobuf\text_format.py", line 474, in Merge text.split('\n'.encode()), TypeError: Can't convert 'bytes' object to str implicitly

please someone can help my problem, thanx

SeungHwa92 avatar Mar 14 '17 10:03 SeungHwa92

I am experiencing this as well. Did you happen to find a solution? I am on Windows 10 with Anaconda.

joshpeng avatar Mar 16 '17 22:03 joshpeng

I also use Anaconda3 on Windows10, but I did not solve this problem yet.

SeungHwa92 avatar Mar 17 '17 01:03 SeungHwa92

I just tested this on an AWS linux machine. The issue also happens when using Python 3. When using Python 2, it works. Unfortunately on Windows though, we can only use TensorFlow with Python 3.

joshpeng avatar Mar 17 '17 17:03 joshpeng

In kaffe\graph.py:

def load(self): '''Load the layer definitions from the prototxt.''' self.params = get_caffe_resolver().NetParameter() with open(self.def_path, 'rb') as def_file: text_format.Merge(def_file.read(), self.params)

change the 'rb' to 'r'.

I think it should help

ohadlights avatar May 14 '17 09:05 ohadlights

@ohadlights fix leads to the following error for me:

$ ./convert.py examples/mnist/lenet.prototxt --code-output-path=mynet.py
Traceback (most recent call last):
  File "./convert.py", line 60, in <module>
    main()
  File "./convert.py", line 56, in main
    args.phase)
  File "./convert.py", line 27, in convert
    transformer = TensorFlowTransformer(def_path, caffemodel_path, phase=phase)
  File "/home/kevin/Deadpool/Convert/caffe-tensorflow-master/kaffe/tensorflow/transformer.py", line 221, in __init__
    self.load(def_path, data_path, phase)
  File "/home/kevin/Deadpool/Convert/caffe-tensorflow-master/kaffe/tensorflow/transformer.py", line 254, in load
    print_stderr(self.graph)
  File "/home/kevin/Deadpool/Convert/caffe-tensorflow-master/kaffe/errors.py", line 7, in print_stderr
    sys.stderr.write('%s\n' % msg)
  File "/home/kevin/Deadpool/Convert/caffe-tensorflow-master/kaffe/graph.py", line 125, in __str__
    tuple(out_shape)))
TypeError: unsupported format string passed to tuple.__format__

johnsrude avatar Aug 10 '17 17:08 johnsrude

May be this solution may help you fix.. First, you should use Linux such as Ubuntu 16.04 Then, you can use conda to create and control the env.

In this case

conda create -n caffe-tf python=2 tensorflow caffe
source activate caffe-tf

Hope it helps

FrancisGee avatar Oct 16 '17 09:10 FrancisGee

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

@johnsrude I am facing the same problem, do u have any solutions now?

ginger0106 avatar Feb 28 '18 08:02 ginger0106