hyperspectral-reconstruction icon indicating copy to clipboard operation
hyperspectral-reconstruction copied to clipboard

[Pytorch+fastai]Code problem

Open msn321 opened this issue 3 years ago • 3 comments

 Hello, recently, I was fortunate enough to read your article _mxr-u-nets for real time hyperspectral reconstruction_. I am very interested in your research. At the same time, I also read the code you published. According to your code, I have studied, but encountered the following problems, I would like to ask you.

Here is my question:

  1. When I open the program file, I found that many packages were not imported. Here are some packages I imported. train.py: `from functools import partial
    from fastai.callback.tracker import SaveModelCallback from fastai.layers import NormType
    from fastai.vision.learner import unet_learner
    import torch.nn.functional as F
    from fastai.vision import models
    import sys

data.py: import matplotlib.pyplot as plt
import torch.nn.functional as F
import sys
from fastcore.utils import ifnone
from pyparsing import Optional
from torchvision.models.detection.image_list import ImageList from traitlets import Tuple
from fastai.torch_core import tensor`

2.When I ran the train.py file, because I added the following statements, a new error occurred. Have you encountered it? Is there a solution? from fastcore.utils import ifnone from pyparsing import Optional from torchvision.models.detection.image_list import ImageList from traitlets import Tuple New error: File "D:/github/PixxelAI/train.py", line 48, in from data import * File "D:\github\PixxelAI\data.py", line 73, in class HSImageListTIFF(ImageList): File "D:\github\PixxelAI\data.py", line 78, in HSImageListTIFF def show_xys(self, xs, ys, imgsize:int=4, figsize:Optional[Tuple[int,int]]=None, **kwargs): TypeError: 'type' object is not subscriptable

  1. utils.py: In this file, there are the following statements: from fastai.vision import Rank0Tensor from fastai.vision import flatten_check But when I was studying, an error message appeared, as shown below: File "D:/github/PixxelAI/utils.py", line 6, in from fastai.vision import Rank0Tensor ImportError: cannot import name 'Rank0Tensor' from 'fastai.vision'

File "D:/github/PixxelAI/utils.py", line 7, in from fastai.vision import flatten_check ImportError: cannot import name 'flatten_check' from 'fastai.vision' I made changes, I don’t know if it’s possible, as shown below: from fastai.torch_core import Tensor from fastai.layers import flatten_check 4. feature.py: In this file, there are the following statements: from fastai.torch_core import requires_grad, children from fastai.callbacks.hooks import hook_outputs

But when I was studying, an error message appeared, as shown below: from fastai.torch_core import requires_grad, children ImportError: cannot import name'children' from'fastai.torch_core'

from fastai.torch_core import requires_grad, children ImportError: cannot import name'children' from'fastai.torch_core' Have you encountered such a problem, and how did you correct it?

Now, it's hard for me to solve these problems. Looking forward to your answers.

msn321 avatar Sep 08 '20 07:09 msn321

 Hello, recently, I was fortunate enough to read your article _mxr-u-nets for real time hyperspectral reconstruction_. I am very interested in your research. At the same time, I also read the code you published. According to your code, I have studied, but encountered the following problems, I would like to ask you.

Here is my question:

  1. When I open the program file, I found that many packages were not imported. Here are some packages I imported. train.py: `from functools import partial from fastai.callback.tracker import SaveModelCallback from fastai.layers import NormType from fastai.vision.learner import unet_learner import torch.nn.functional as F from fastai.vision import models import sys

data.py: import matplotlib.pyplot as plt import torch.nn.functional as F import sys from fastcore.utils import ifnone from pyparsing import Optional from torchvision.models.detection.image_list import ImageList from traitlets import Tuple from fastai.torch_core import tensor`

2.When I ran the train.py file, because I added the following statements, a new error occurred. Have you encountered it? Is there a solution? from fastcore.utils import ifnone from pyparsing import Optional from torchvision.models.detection.image_list import ImageList from traitlets import Tuple New error: File "D:/github/PixxelAI/train.py", line 48, in from data import * File "D:\github\PixxelAI\data.py", line 73, in class HSImageListTIFF(ImageList): File "D:\github\PixxelAI\data.py", line 78, in HSImageListTIFF def show_xys(self, xs, ys, imgsize:int=4, figsize:Optional[Tuple[int,int]]=None, **kwargs): TypeError: 'type' object is not subscriptable

  1. utils.py: In this file, there are the following statements: from fastai.vision import Rank0Tensor from fastai.vision import flatten_check But when I was studying, an error message appeared, as shown below: File "D:/github/PixxelAI/utils.py", line 6, in from fastai.vision import Rank0Tensor ImportError: cannot import name 'Rank0Tensor' from 'fastai.vision'

File "D:/github/PixxelAI/utils.py", line 7, in from fastai.vision import flatten_check ImportError: cannot import name 'flatten_check' from 'fastai.vision' I made changes, I don’t know if it’s possible, as shown below: from fastai.torch_core import Tensor from fastai.layers import flatten_check 4. feature.py: In this file, there are the following statements: from fastai.torch_core import requires_grad, children from fastai.callbacks.hooks import hook_outputs

But when I was studying, an error message appeared, as shown below: from fastai.torch_core import requires_grad, children ImportError: cannot import name'children' from'fastai.torch_core'

from fastai.torch_core import requires_grad, children ImportError: cannot import name'children' from'fastai.torch_core' Have you encountered such a problem, and how did you correct it?

Now, it's hard for me to solve these problems. Looking forward to your answers.

how is finished the problems? we are one

Never-up avatar May 10 '21 05:05 Never-up

In util.py:

def MRAE(pred:Tensor, targ:Tensor)->Rank0Tensor:
    "Mean Relative Absolute Error between `pred` and `targ`"
    pred, targ = flatten_check(pred, targ)
    return (torch.abs(pred - targ) / (targ + 1e-8)).mean()

class MRAELoss(nn.Module):
    def forward(self, pred, targ):
        pred, targ = flatten_check(pred, targ)
        return (torch.abs(pred - targ) / (targ + 1e-8)).mean()

class MRSELoss(nn.Module):
    def forward(self, pred, targ):
#         pred, targ = flatten_check(pred, targ)
#         return 0.5*((pred-targ)**2/(targ + 1e-8)).mean()
        return (((pred-targ)/(targ + 1e-8))**2).mean()

Why do these loss function have 1e-8?

liuyulvv avatar Nov 19 '21 15:11 liuyulvv

因为高光谱数据的取值范围是[0,1],(targ + 1e-8),加上极小值1e-8,是为了防止分母为0的情况。

------------------ 原始邮件 ------------------ 发件人: "akashpalrecha/hyperspectral-reconstruction" @.>; 发送时间: 2021年11月19日(星期五) 晚上11:53 @.>; @.@.>; 主题: Re: [akashpalrecha/hyperspectral-reconstruction] [Pytorch+fastai]Code problem (#1)

In util.py: def MRAE(pred:Tensor, targ:Tensor)->Rank0Tensor: "Mean Relative Absolute Error between pred and targ" pred, targ = flatten_check(pred, targ) return (torch.abs(pred - targ) / (targ + 1e-8)).mean() class MRAELoss(nn.Module): def forward(self, pred, targ): pred, targ = flatten_check(pred, targ) return (torch.abs(pred - targ) / (targ + 1e-8)).mean() class MRSELoss(nn.Module): def forward(self, pred, targ): # pred, targ = flatten_check(pred, targ) # return 0.5*((pred-targ)**2/(targ + 1e-8)).mean() return (((pred-targ)/(targ + 1e-8))**2).mean()

Why do these loss function have 1e-8?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

msn321 avatar Nov 20 '21 06:11 msn321