caffemodel2pytorch icon indicating copy to clipboard operation
caffemodel2pytorch copied to clipboard

AttributeError: module 'google.protobuf.descriptor' has no attribute '_message'

Open lunasdejavu opened this issue 5 years ago • 5 comments

what is the version of the protobuf you use? I just copied

import torch
from caffemodel2pytorch import caffemodel2pytorch

model = caffemodel2pytorch.Net(
	prototxt = 'mobilenet_deploy.prototxt',
	weights = 'mobilenet.caffemodel',
	caffe_proto = 'https://raw.githubusercontent.com/BVLC/caffe/master/src/caffe/proto/caffe.proto'
)
model.cuda()
model.eval()
torch.set_grad_enabled(False)

it just showed the error :

Traceback (most recent call last):
  File "test_torch.py", line 7, in <module>
    caffe_proto = 'https://raw.githubusercontent.com/BVLC/caffe/master/src/caffe
/proto/caffe.proto'
  File "C:\LPR\MobileNet-Caffe\caffemodel2pytorch\caffemodel2pytorch.py", line 7
1, in __init__
    self.net_param = initialize(caffe_proto).NetParameter()
  File "C:\LPR\MobileNet-Caffe\caffemodel2pytorch\caffemodel2pytorch.py", line 4
1, in initialize
    old_pool = google.protobuf.descriptor._message.default_pool
AttributeError: module 'google.protobuf.descriptor' has no attribute '_message'

lunasdejavu avatar Jun 11 '19 05:06 lunasdejavu

I haven't used this code since a long time ago, so I can't find the good protobuf version unfortunately.

You may also comment all these backup/restore protobuf lines. They are needed only in some cases of integrating with existing caffe.python-using code. You may also check out protobuf commit history at github and find when this was changed (you may also lookup the dates when I created this repo).

vadimkantorov avatar Jun 11 '19 05:06 vadimkantorov

I tried with protobuf version 3.7 it works

chason94 avatar Nov 04 '19 09:11 chason94

I had this problem, for me the python version I was using was too recent for the protobuf version. I solved this by creating a virtual environment with python 3.7 and protobuf version 3.14

Joe-Surrey avatar Jan 14 '21 10:01 Joe-Surrey

Unfortunately, I even don't remember why I had to do those Protobuf hacks :( If someone solves the problems with recent python / protobuf, please feel free to send a pr. Maybe commenting out the old_*-related lines actually does work

vadimkantorov avatar Jan 14 '21 12:01 vadimkantorov

#24 I have solved the problem by discovering a logic redundency among line 41 43 44 46, which can avoid using _message. Please check and accept my pull request. I haved tested the code with one .caffeemodel file.

penway avatar Sep 14 '22 09:09 penway