Failed to include caffe_pb2, things might go wrong! ... TypeError: expected bytes, str found 2019-09-04 17:03:54

使用python的caffe的时候,出现下面的问题:

Failed to include caffe_pb2, things might go wrong!
Traceback (most recent call last):
  File "caffe/python/draw_net.py", line 8, in <module>
    import caffe
  File "/home/caffe/python/caffe/__init__.py", line 4, in <module>
    from .proto.caffe_pb2 import TRAIN, TEST
  File "/home/caffe/python/caffe/proto/caffe_pb2.py", line 17, in <module>
    serialized_pb=''# 一个很长的字符串,太长了,就不贴上来了
  File "/usr/local/anaconda3/lib/python3.5/site-packages/google/protobuf/descriptor.py", line 879, in __new__
    return _message.default_pool.AddSerializedFile(serialized_pb)
TypeError: expected bytes, str found

参考了一下《caffe cpu版 Anaconda3 python 接口安装》,猜测原装的protobuf可能只能用于python2,所以决定重新安装python3能用的protobuf

~$ # 先卸载旧版本
~$ sudo pip uninstall protobuf
~$ # 再安装py3版本
~$ sudo pip install protobuf-py3

之后问题得到解决。

目前caffe对于python2.7支持较好,所以flownet2的caffe版本安装多在python2.7实现,近期笔者需要用到python3环境下的flownet2,因此本文介绍在python3中安装GPU的flownet2。 代码地址 https://github.com/lmb-freiburg/flownet2 安装环境 python3.6 + CUDA9.0 + Cudnn7.4... line = ‘’.join(line.split()) TypeError: sequence item 0: expected str instance, bytes found 修改后代码: line=str(line) line = ‘’.join(line.split()) File “h5py_objects.pyx”, line 54, in h5py._objects.with_phil.wrapper File “h5py_objects.pyx”, line 55, in h5py._objects.with_phil.wrapper File “h5py\h5f.pyx”, line 83, in h5py.h5f.open TypeError: expected bytes, str found 将h5py.h5f.open(filename, f 调python代码遇到的问题 1.return _message.default_pool.AddSerializedFile(serialized_pb) TypeError: expected bytes, str found 解决方法:serialized_pb = b'字符串内容' 或者"字符串".encode('utf-8') 2.ModuleNotFoundError: No mo... Failed to include caffe_pb2, things might go wrong! Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/david/download/caffe-master/python/caffe/__init_... protobuf千万不要用conda install来安装,要用~/anaconda2/bin/pip install protobuf 安装,不然import caffe会出现ImportError: No mo... 解决方法:在Anaconda Prompt 搜索protobuf库: conda search protobuf 然后找到与虚拟环境里python版本相对应的protobuf版本。例如python3.6相对应的protobuf=3.1.0 1. 为什么要使用cython? cython官方网站给出的解释: [Cython] is a programming language that makes writing C extensions for the Python language as easy as Python itself. It aims to become a superset of the [Python] language which 这是学习笔记,我把遇到的 draw_net.py 各类问题集中说明一下: 1、错误关键词:ImportError: /homedata/aistudy_data/caffe_data/caffe-master/python/caffe/_caffe.so: undefined symbol: _ZN5caffe3 详细描述: /homedata/aistudy_data/caffe_dat...