Initializing Datasets and Dataloaders...
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
Params to learn:
classifier.1.weight
classifier.1.bias
Epoch 0/1
----------
train Loss: 0.7456 Acc: 0.4918
Traceback (most recent call last):
File "F:/python_learn/pytorch_learn/transfer_learning/finetuning_convent.py", line 494, in
model_ft,hist = train_model(model_ft,dataloaders_dict,criterion,optimizer_ft,num_epochs,is_inception = (model_name=="inception"))
File "F:/python_learn/pytorch_learn/transfer_learning/finetuning_convent.py", line 150, in train_model
for inputs,labels in dataloaders[phase_]:
File "D:\tools\conda\envs\torch\lib\site-packages\torch\utils\data\dataloader.py", line 582, in __next__
return self._process_next_batch(batch)
File "D:\tools\conda\envs\torch\lib\site-packages\torch\utils\data\dataloader.py", line 608, in _process_next_batch
raise batch.exc_type(batch.exc_msg)
UnboundLocalError: Traceback (most recent call last):
File "D:\tools\conda\envs\torch\lib\site-packages\torch\utils\data\_utils\worker.py", line 99, in _worker_loop
samples = collate_fn([dataset[i] for i in batch_indices])
File "D:\tools\conda\envs\torch\lib\site-packages\torch\utils\data\_utils\worker.py", line 99, in
samples = collate_fn([dataset[i] for i in batch_indices])
File "D:\tools\conda\envs\torch\lib\site-packages\torchvision\datasets\folder.py", line 130, in __getitem__
sample = self.loader(path)
File "D:\tools\conda\envs\torch\lib\site-packages\torchvision\datasets\folder.py", line 166, in default_loader
return pil_loader(path)
File "D:\tools\conda\envs\torch\lib\site-packages\torchvision\datasets\folder.py", line 148, in pil_loader
img = Image.open(f)
File "D:\tools\conda\envs\torch\lib\site-packages\PIL\Image.py", line 2690, in open
im = _open_core(fp, filename, prefix)
File "D:\tools\conda\envs\torch\lib\site-packages\PIL\Image.py", line 2676, in _open_core
im = factory(fp, filename)
File "D:\tools\conda\envs\torch\lib\site-packages\PIL\JpegImagePlugin.py", line 783, in jpeg_factory
im = JpegImageFile(fp, filename)
File "D:\tools\conda\envs\torch\lib\site-packages\PIL\ImageFile.py", line 103, in __init__
self._open()
File "D:\tools\conda\envs\torch\lib\site-packages\PIL\JpegImagePlugin.py", line 373, in _open
handler(self, i)
File "D:\tools\conda\envs\torch\lib\site-packages\PIL\JpegImagePlugin.py", line 139, in APP
self.info["photoshop"] = photoshop
【出现问题】:UnboundLocalError: local variable 'photoshop' referenced before assignment
【解决办法】:
1、一般不追踪错误过程出现此错误提示,如果variable确实是重定义的变量,那就是全局变量、局部变量指派不清,可用global指明。
2.这里看到是PIL也就是6.0.0版本的Pillow的问题,降为5.41之类的
参考:https://stackoverflow.com/questions/56587941/unboundlocalerror-local-variable-photoshop-referenced-before-assignment