如何创建一个以未标记 "dummy data" 作为输入的网络?
How to create a net which takes unlabeled "dummy data" as input?
我目前正在通过 caffe/examples/
学习更多关于 caffe/pycaffe
的信息。
在 02-fine-tuning.ipynb-notebook
中有一个代码单元,展示了如何创建一个将未标记 "dummmy data"
作为输入的 caffenet,允许我们在外部设置其输入图像。笔记本可以在这里找到:
https://github.com/BVLC/caffe/blob/master/examples/02-fine-tuning.ipynb
There is a given code-cell, which throws an error:
dummy_data = L.DummyData(shape=dict(dim=[1, 3, 227, 227]))
imagenet_net_filename = caffenet(data=dummy_data, train=False)
imagenet_net = caffe.Net(imagenet_net_filename, weights, caffe.TEST)
error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-9f0ecb4d95e6> in <module>()
1 dummy_data = L.DummyData(shape=dict(dim=[1, 3, 227, 227]))
----> 2 imagenet_net_filename = caffenet(data=dummy_data, train=False)
3 imagenet_net = caffe.Net(imagenet_net_filename, weights, caffe.TEST)
<ipython-input-5-53badbea969e> in caffenet(data, label, train, num_classes, classifier_name, learn_all)
68 # write the net to a temporary file and return its filename
69 with tempfile.NamedTemporaryFile(delete=False) as f:
---> 70 f.write(str(n.to_proto()))
71 return f.name
~/anaconda3/envs/testcaffegpu/lib/python3.6/tempfile.py in func_wrapper(*args, **kwargs)
481 @_functools.wraps(func)
482 def func_wrapper(*args, **kwargs):
--> 483 return func(*args, **kwargs)
484 # Avoid closing the file as long as the wrapper is alive,
485 # see issue #18879.
TypeError: a bytes-like object is required, not 'str'
有人知道怎么做吗?
tempfile.NamedTemporaryFile() 默认以二进制模式 ('w+b') 打开文件。由于您使用的是 Python3.x,字符串与 Python 2.x 的类型不同,因此提供字符串作为 f.write() 的输入会导致错误,因为它需要字节.覆盖二进制模式应该可以避免这个错误。
替换
with tempfile.NamedTemporaryFile(delete=False) as f:
与
with tempfile.NamedTemporaryFile(delete=False, mode='w') as f:
这在之前的post中已经解释过:
TypeError: 'str' does not support the buffer interface
我目前正在通过 caffe/examples/
学习更多关于 caffe/pycaffe
的信息。
在 02-fine-tuning.ipynb-notebook
中有一个代码单元,展示了如何创建一个将未标记 "dummmy data"
作为输入的 caffenet,允许我们在外部设置其输入图像。笔记本可以在这里找到:
https://github.com/BVLC/caffe/blob/master/examples/02-fine-tuning.ipynb
There is a given code-cell, which throws an error:
dummy_data = L.DummyData(shape=dict(dim=[1, 3, 227, 227]))
imagenet_net_filename = caffenet(data=dummy_data, train=False)
imagenet_net = caffe.Net(imagenet_net_filename, weights, caffe.TEST)
error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-6-9f0ecb4d95e6> in <module>()
1 dummy_data = L.DummyData(shape=dict(dim=[1, 3, 227, 227]))
----> 2 imagenet_net_filename = caffenet(data=dummy_data, train=False)
3 imagenet_net = caffe.Net(imagenet_net_filename, weights, caffe.TEST)
<ipython-input-5-53badbea969e> in caffenet(data, label, train, num_classes, classifier_name, learn_all)
68 # write the net to a temporary file and return its filename
69 with tempfile.NamedTemporaryFile(delete=False) as f:
---> 70 f.write(str(n.to_proto()))
71 return f.name
~/anaconda3/envs/testcaffegpu/lib/python3.6/tempfile.py in func_wrapper(*args, **kwargs)
481 @_functools.wraps(func)
482 def func_wrapper(*args, **kwargs):
--> 483 return func(*args, **kwargs)
484 # Avoid closing the file as long as the wrapper is alive,
485 # see issue #18879.
TypeError: a bytes-like object is required, not 'str'
有人知道怎么做吗?
tempfile.NamedTemporaryFile() 默认以二进制模式 ('w+b') 打开文件。由于您使用的是 Python3.x,字符串与 Python 2.x 的类型不同,因此提供字符串作为 f.write() 的输入会导致错误,因为它需要字节.覆盖二进制模式应该可以避免这个错误。
替换
with tempfile.NamedTemporaryFile(delete=False) as f:
与
with tempfile.NamedTemporaryFile(delete=False, mode='w') as f:
这在之前的post中已经解释过:
TypeError: 'str' does not support the buffer interface