资讯动态

【python】Python ERROR: TypeError: a bytes-like object is required, not ‘str‘ (tempfile)

发布时间:2026/10/23 1:39:02 来源:尧图企业网站定制
在跑caffe demo的时候遇到的问题具体报错如下--------------------------------------------------------------------------- TypeError Traceback (most recent call last) ipython-input-49-fe99b8f3cc41 in module 1 dummy_data L.DummyData(shapedict(dim[1, 3, 227, 227])) ---- 2 caffenet(datadummy_data, trainFalse) 3 # print(str(caffenet(datadummy_data, trainFalse))) 4 # imagenet_net_filename caffenet(datadummy_data, trainFalse) 5 # print(imagenet_net_filename) ipython-input-48-7c8a9a79285d in caffenet(data, label, train, num_classes, classifier_name, learn_all) 38 # write the net to a temporary file and return its filename 39 with tempfile.NamedTemporaryFile(deleteFalse) as f: --- 40 f.write(str(n.to_proto())) 41 return f.name ~/anaconda3/envs/tensorflow-gpu/lib/python3.7/tempfile.py in func_wrapper(*args, **kwargs) 479 _functools.wraps(func) 480 def func_wrapper(*args, **kwargs): -- 481 return func(*args, **kwargs) 482 # Avoid closing the file as long as the wrapper is alive, 483 # see issue #18879. TypeError: a bytes-like object is required, not str报错位置是--- 40 f.write(str(n.to_proto()))但实际上是需要修改上一行# with tempfile.NamedTemporaryFile(deleteFalse) as f:withtempfile.NamedTemporaryFile(deleteFalse,modew)asf:问题解决

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑