hyperreel icon indicating copy to clipboard operation
hyperreel copied to clipboard

Fail to run the code

Open ZkzMMDC opened this issue 1 year ago • 3 comments

It seems to be some problem with ssim. I don’t know what causes this problem? Can you reply? Thank you very much.

Traceback (most recent call last):
  File "main.py", line 209, in main
    elastic_run(cfg)
  File "main.py", line 204, in elastic_run
    run(cfg, "", "", "")
  File "main.py", line 183, in run
    trainer.fit(system, datamodule=dm)
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 696, in fit
    self._call_and_handle_interrupt(
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 650, in _call_and_handle_interrupt
    return trainer_fn(*args, **kwargs)
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 735, in _fit_impl
    results = self._run(model, ckpt_path=self.ckpt_path)
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1166, in _run
    results = self._run_stage()
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1252, in _run_stage
    return self._run_train()
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1274, in _run_train
    self._run_sanity_check()
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1343, in _run_sanity_check
    val_loop.run()
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/loops/loop.py", line 200, in run
    self.advance(*args, **kwargs)
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/loops/dataloader/evaluation_loop.py", line 155, in advance
    dl_outputs = self.epoch_loop.run(self._data_fetcher, dl_max_batches, kwargs)
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/loops/loop.py", line 200, in run
    self.advance(*args, **kwargs)
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/loops/epoch/evaluation_epoch_loop.py", line 143, in advance
    output = self._evaluation_step(**kwargs)
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/loops/epoch/evaluation_epoch_loop.py", line 240, in _evaluation_step
    output = self.trainer._call_strategy_hook(hook_name, *kwargs.values())
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/trainer/trainer.py", line 1704, in _call_strategy_hook
    output = fn(*args, **kwargs)
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/pytorch_lightning/strategies/strategy.py", line 370, in validation_step
    return self.model.validation_step(*args, **kwargs)
  File "/home/zkz/python/hyperreel-main/nlf/__init__.py", line 1004, in validation_step
    log = self.validation_image(batch, batch_idx)
  File "/home/zkz/python/hyperreel-main/nlf/__init__.py", line 980, in validation_image
    outputs['val/ssim'] = ssim(img.transpose(1, 2, 0), img_gt.transpose(1, 2, 0))
  File "/home/zkz/python/hyperreel-main/metrics.py", line 35, in ssim
    return structural_similarity(np.array(image1), np.array(image0), win_size=11, multichannel=True, gaussian_weights=True, data_range=1.0)
  File "/home/zkz/anaconda3/envs/hyperreel2/lib/python3.8/site-packages/skimage/metrics/_structural_similarity.py", line 178, in structural_similarity
    raise ValueError(
ValueError: win_size exceeds image extent. Either ensure that your images are at least 7x7; or pass win_size explicitly in the function call, with an odd value less than or equal to the smaller side of your images. If your images are multichannel (with color channels), set channel_axis to the axis number corresponding to the channels.

ZkzMMDC avatar Oct 18 '23 09:10 ZkzMMDC

ValueError: win_size exceeds image extent. Either ensure that your images are at least 7x7; or pass win_size explicitly in the function call, with an odd value less than or equal to the smaller side of your images. If your images are multichannel (with color channels), set channel_axis to the axis number corresponding to the channels.

ZkzMMDC avatar Oct 18 '23 09:10 ZkzMMDC

It seems like the images that are being given to the ssim function are the wrong shape, for some reason. I'm not sure why this would be, but I would try printing img.shape on line 980 in main/nlf/__init__.py, and then debugging from there.

benattal avatar Oct 21 '23 16:10 benattal

the problem can be solved bypip install scikit-image==0.19.3

GotFusion avatar Nov 18 '23 12:11 GotFusion