ozantezcan / BSUV-Net-inference

56 stars 13 forks source link

Error when running BSUV-Net 2.0 #7

Open dd2912 opened 3 years ago

dd2912 commented 3 years ago

When I run the model on a video of 576x1008, I get the following error:

RuntimeError: torch.cat(): Sizes of tensors must match except in dimension 0. Got 288 and 576 in dimension 1 (The offending index is 2)

Have you ever encountered this issue? If so, do you have a fix for that?

Thanks

ozantezcan commented 3 years ago

Hi, thanks for your interest in the repo.

I didn't encounter this error. Can you send me the full error log so that I can try to understand what might be the issue? Did you able to run the inference on lower resolution videos (e.g. the example video in the repo)?

Sun-Xinnnnn commented 2 years ago

Loading weights for net_encoder Loading weights for net_decoder [ERROR:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap.cpp (415) cv::VideoWriter::open VIDEOIO(CV_IMAGES): raised OpenCV exception:

OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\videoio\src\cap_images.cpp:253: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): output in function 'cv::icvExtractPattern'

Traceback (most recent call last): File "inference.py", line 46, in for inp in tensor_loader: File "D:\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 345, in next data = self._next_data() File "D:\Anaconda3\lib\site-packages\torch\utils\data\dataloader.py", line 385, in _next_data data = self._dataset_fetcher.fetch(index) # may raise StopIteration File "D:\Anaconda3\lib\site-packages\torch\utils\data_utils\fetch.py", line 28, in fetch data.append(next(self.dataset_iter)) File "C:\Users\Administrator\Desktop\BSUV-Net-inference-master\BSUV-Net-inference-master\utils\dataloader.py", line 148, in iter inp, = transform(inp, fr[:, :, :1]) File "C:\Users\Administrator\Desktop\BSUV-Net-inference-master\BSUV-Net-inference-master\utils\augmentations.py", line 254, in call inp_tensor = torch.cat(inp_tensors, dim=0) RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 288 and 368 in dimension 1 at C:\w\1\s\tmp_conda_3.7_100118\conda\conda-bld\pytorch_1579082551706\work\aten\src\TH/generic/THTensor.cpp:612

Sun-Xinnnnn commented 2 years ago

I also have this problem ,Have you ever encountered this issue?

ArtistBanda commented 2 years ago

Hi, so using the example video frame which is of size 352 × 288 works fine but for using any other input stream of video it seems to break and throws the same error as above. Could you please help with that @ozantezcan ? And there are places in the code where you change h,w to valid_h, valid_w with this int(h / 16) * 16, could you please help me understand what does it do and why do we need it?

dulre159 commented 2 years ago

I have the same problem. Everything works if input video has the resolution of 352x288 like the example videos. It does not work with other resolutions.

xavibou commented 2 years ago

The VideoLoader class in data_loader.py reads all frames and resizes them to 288x352 resolution. I managed to make it work by modifying the def __readRGB method as follows:

def __readRGB(self, path): assert os.path.exists(path), "{} does not exist".format(path) im = cv2.cvtColor(cv2.resize(cv2.imread(path), self.size), cv2.COLOR_BGR2RGB).astype(np.float)/255

where self.size is (256, 256) in my case. This works for me on videos and frames of different resolution.