xyupeng / ContrastiveCrop

[CVPR 2022 Oral] Crafting Better Contrastive Views for Siamese Representation Learning

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

请问TypeError: forward() missing 1 required positional argument: 'box',这个box参数具体我应该传什么参数

syfffffff opened this issue · comments

Would you please let me know in which config/job you met the problem?

I added this code to the TSN network and added it to the training part, but the 'box' parameter was abnormal when calling

def get_augmentation(self): if self.modality == 'RGB': return torchvision.transforms.Compose([ GroupMultiScaleCrop(self.input_size, [1, .875, .75, .66]), GroupRandomHorizontalFlip(is_flow=False), # 增加数据增强 ContrastiveCrop(size=32, scale=(0.2, 1.0)) ])

Traceback (most recent call last): File "D:\download\TSN-pytorch\main.py", line 165, in <module> main() File "D:\download\TSN-pytorch\main.py", line 139, in main train(args.record_path,train_loader, model, criterion, optimizer, epoch, args.clip_gradient) File "D:\download\TSN-pytorch\train.py", line 18, in train for i, (data, target) in enumerate(train_loader): File "C:\Users\lenovo\anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 521, in __next__ data = self._next_data() File "C:\Users\lenovo\anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 561, in _next_data data = self._dataset_fetcher.fetch(index) # may raise StopIteration File "C:\Users\lenovo\anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "C:\Users\lenovo\anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "D:\download\TSN-pytorch\dataset\dataset.py", line 67, in __getitem__ return self._get(record, segment_indices) File "D:\download\TSN-pytorch\dataset\dataset.py", line 122, in _get process_data = self.transform(images) File "C:\Users\lenovo\anaconda3\envs\pytorch\lib\site-packages\torchvision\transforms\transforms.py", line 60, in __call__ img = t(img) File "C:\Users\lenovo\anaconda3\envs\pytorch\lib\site-packages\torchvision\transforms\transforms.py", line 60, in __call__ img = t(img) File "C:\Users\lenovo\anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl return forward_call(*input, **kwargs) TypeError: forward() missing 1 required positional argument: 'box'

这是报的错误,谢谢

You should pass a tuple/list (h_min, w_min, h_max, w_max) normalized in [0, 1] which indicates the box, as in this code.

Sorry to bother you. I had the same problem, but I still didn't fix it. This is my original code.

trans_list = [ContrastiveCrop(alpha=0.6, size=224, scale=(0.2, 1.0))]    
data_transform_2 = transforms.Compose(trans_list)

pic = data_transform_2(img_test)
plt.imshow(pic)           
plt.show()

I was just trying to visualize the ContrastiveCrop. I also added box after img_test, but I still get an error.

trans_list = [ContrastiveCrop(alpha=0.6, size=224, scale=(0.2, 1.0))]    
data_transform_2 = transforms.Compose(trans_list)

pic = data_transform_2(img_test, [0.1, 0.1, 0.9, 0.9])
plt.imshow(pic)           
plt.show()

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-81-0001e52f5c9e> in <module>
      2 data_transform_2 = transforms.Compose(trans_list)
      3 
----> 4 pic = data_transform_2(img_test, [0.1, 0.1, 0.9, 0.9])
      5 plt.imshow(pic)
      6 plt.show()

TypeError: __call__() takes 2 positional arguments but 3 were given

Please try CCompose instead, which takes box for the first transformation.