caffemodel2pytorch icon indicating copy to clipboard operation
caffemodel2pytorch copied to clipboard

TypeError: expected str, bytes or os.PathLike object, not NoneType

Open NazarovAV opened this issue 4 years ago • 7 comments

Hi! I'm trying to run your example "Imitate pycaffe interface to help in porting", but an error pops up

Traceback (most recent call last): File "py.py", line 9, in net = caffe.Net('tracker.prototxt', caffe.TEST, weights = 'tracker.caffemodel') File "/media/veracrypt1/work/examples/trackers/caffemodel2pytorch-master/caffemodel2pytorch.py", line 71, in init self.net_param = initialize(caffe_proto).NetParameter() File "/media/veracrypt1/work/examples/trackers/caffemodel2pytorch-master/caffemodel2pytorch.py", line 33, in initialize local_caffe_proto = os.path.join(codegen_dir, os.path.basename(caffe_proto)) File "/usr/local/lib/python3.7/posixpath.py", line 146, in basename p = os.fspath(p) TypeError: expected str, bytes or os.PathLike object, not NoneType

NazarovAV avatar Feb 10 '20 11:02 NazarovAV

It seems that either codegen_dir or caffe_proto are None. Could you please put in a print(codegen_dir, caffe_proto) before the local_caffe_proto = ... line and paste in here what it prints?

vadimkantorov avatar Feb 10 '20 11:02 vadimkantorov

Yes, caffe_proto was None. I've added flag "caffe_proto = 'https://raw.githubusercontent.com/BVLC/caffe/master/src/caffe/proto/caffe.proto'" and fixed a couple of mistakes "AttributeError: 'OSError' object has no attribute 'message'" and "UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa2 in position 31: invalid start byte". Now i get the message: "Skipping layer [concat, Concat, Concat]: not found in caffemodel2pytorch.modules dict Skipping layer [neg, Power, Power]: not found in caffemodel2pytorch.modules dict Skipping layer [flatten, Flatten, Flatten]: not found in caffemodel2pytorch.modules dict Skipping layer [abssum, Reduction, Reduction]: not found in caffemodel2pytorch.modules dict caffemodel2pytorch: loading model from [tracker.caffemodel] in HDF5 format failed [], falling back to caffemodel format caffemodel2pytorch: loaded model from [tracker.caffemodel] in caffemodel format Traceback (most recent call last): File "py.py", line 13, in blobs_out = net.forward(data = np.zeros((8, 3, 224, 224), dtype = np.float32)) File "/media/veracrypt1/work/examples/trackers/caffemodel2pytorch-master/caffemodel2pytorch.py", line 119, in forward assert name in variables, 'Variable [{}] does not exist. Pass it as a keyword argument or provide a layer which produces it.'.format(name) AssertionError: Variable [target] does not exist. Pass it as a keyword argument or provide a layer which produces it."

NazarovAV avatar Feb 10 '20 11:02 NazarovAV

AssertionError: Variable [target] does not exist. Pass it as a keyword argument or provide a layer which produces it." basically this is it. It seems that your model wants to compute some loss with ground truth "target" - either you should write some code that would modify the network prior to forward pass or you should provide it with some (dummy?) target variables

vadimkantorov avatar Feb 10 '20 12:02 vadimkantorov

You should also decide if you want to provide pytorch equivalents of these modules:

"Skipping layer [concat, Concat, Concat]: not found in caffemodel2pytorch.modules dict
Skipping layer [neg, Power, Power]: not found in caffemodel2pytorch.modules dict
Skipping layer [flatten, Flatten, Flatten]: not found in caffemodel2pytorch.modules dict
Skipping layer [abssum, Reduction, Reduction]: not found in caffemodel2pytorch.modules dict

vadimkantorov avatar Feb 10 '20 12:02 vadimkantorov

If you do, please don't hesitate to send a PR - the codebase would improve from some porting to Python3 and more modern PyTorch

vadimkantorov avatar Feb 10 '20 12:02 vadimkantorov

  1. Line #139: Comment or remove e.message
  2. Line #140: Change to bytes_weights = open(weights, 'rb').read()

These two change worked for me. Env: Pytorch: 1.5, Python: 3.6.9, Google Colab

abhisheksambyal avatar May 29 '20 01:05 abhisheksambyal

@abhisheksambyal Please send a PR, I'll merge these

vadimkantorov avatar May 29 '20 11:05 vadimkantorov