如何解决ValueError:图块无法扩展到图像pytorch之外
在训练模型时,我正在将NumPy数组作为图像加载到PyTorch中,这给了我这个错误,我尝试了所有操作,但找不到帮助...,我正在训练分类器模型..... ................................................... ................................................... ................................................... .........................
ValueError Traceback (most recent call last)
<ipython-input-12-b4d3f7be01c1> in <module>
1 # training
----> 2 trained_model = train(n_epochs,np.Inf,loaders,model,optimizer,criterion)
<ipython-input-10-b4d180a2c041> in train(n_epochs,valid_loss_min_input,criterion,device,checkpoint_path,best_model_path)
29 ###################
30 model.train()
---> 31 for batch_idx,(data,target) in enumerate(loaders['train']):
32 # move to gpu
33 data,target = data.to(device),target.to(device)
G:\anaconda3\envs\data_env\lib\site-packages\torch\utils\data\DataLoader.py in __next__(self)
343
344 def __next__(self):
--> 345 data = self._next_data()
346 self._num_yielded += 1
347 if self._dataset_kind == _DatasetKind.Iterable and \
G:\anaconda3\envs\data_env\lib\site-packages\torch\utils\data\DataLoader.py in _next_data(self)
383 def _next_data(self):
384 index = self._next_index() # may raise stopiteration
--> 385 data = self._dataset_fetcher.fetch(index) # may raise stopiteration
386 if self._pin_memory:
387 data = _utils.pin_memory.pin_memory(data)
G:\anaconda3\envs\data_env\lib\site-packages\torch\utils\data\_utils\fetch.py in fetch(self,possibly_batched_index)
42 def fetch(self,possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]
G:\anaconda3\envs\data_env\lib\site-packages\torch\utils\data\_utils\fetch.py in <listcomp>(.0)
42 def fetch(self,possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]
G:\anaconda3\envs\data_env\lib\site-packages\torchvision\datasets\folder.py in __getitem__(self,index)
135 sample = self.loader(path)
136 if self.transform is not None:
--> 137 sample = self.transform(sample)
138 if self.target_transform is not None:
139 target = self.target_transform(target)
G:\anaconda3\envs\data_env\lib\site-packages\torchvision\transforms\transforms.py in __call__(self,img)
59 def __call__(self,img):
60 for t in self.transforms:
---> 61 img = t(img)
62 return img
63
<ipython-input-3-88cdee8f0d6c> in __call__(self,img)
7 im = np.asarray(img)
8 im = detect(im)
----> 9 img = Image.fromarray(im)
10 img = img.resize(size=(128,128))
11 return img
G:\anaconda3\envs\data_env\lib\site-packages\PIL\Image.py in fromarray(obj,mode)
2768 obj = obj.tostring()
2769
-> 2770 return frombuffer(mode,size,obj,"raw",rawmode,1)
2771
2772
G:\anaconda3\envs\data_env\lib\site-packages\PIL\Image.py in frombuffer(mode,data,decoder_name,*args)
2708 return im
2709
-> 2710 return frombytes(mode,args)
2711
2712
G:\anaconda3\envs\data_env\lib\site-packages\PIL\Image.py in frombytes(mode,*args)
2648
2649 im = new(mode,size)
-> 2650 im.frombytes(data,args)
2651 return im
2652
G:\anaconda3\envs\data_env\lib\site-packages\PIL\Image.py in frombytes(self,*args)
795 # unpack data
796 d = _getdecoder(self.mode,args)
--> 797 d.setimage(self.im)
798 s = d.decode(data)
799
ValueError: tile cannot extend outside the image
在自定义函数中,我试图对图像进行预处理,然后调用它 当我测试加载一小部分用于显示的代码时,效果很好
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。