Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

predict.py报错 #4

Open
m47777 opened this issue Aug 22, 2023 · 2 comments
Open

predict.py报错 #4

m47777 opened this issue Aug 22, 2023 · 2 comments

Comments

@m47777
Copy link

m47777 commented Aug 22, 2023

作者您好,我在跑predict.py的时候时间过长,在加载完数据集后报了一个warning:RuntimeWarning: invalid value encountered in true_divide,查看报错位置是t = a + (bands[i, :, :] - c) * (b - a) / (d - c),目前加了代码np.seterr(divide='ignore',invalid='ignore')忽略这个报错,但是还是时间过长,没有结果。请问您有遇到过这个问题以及解决办法吗T-T

@Phoenix-Shen
Copy link
Owner

Phoenix-Shen commented Aug 22, 2023

出错

作者您好,我在跑predict.py的时候时间过长,在加载完数据集后报了一个warning:RuntimeWarning: invalid value encountered in true_divide,查看报错位置是t = a + (bands[i, :, :] - c) * (b - a) / (d - c),目前加了代码np.seterr(divide='ignore',invalid='ignore')忽略这个报错,但是还是时间过长,没有结果。请问您有遇到过这个问题以及解决办法吗T-T

出错地方是将源数据格式uint16转成uint8,这段代码:

def uint16to8(bands, lower_percent=0.001, higher_percent=99.999): 
    out = np.zeros_like(bands,dtype = np.uint8) 
    n = bands.shape[0] 
    for i in range(n): 
        a = 0 # np.min(band) 
        b = 255 # np.max(band) 
        c = np.percentile(bands[i, :, :], lower_percent) 
        d = np.percentile(bands[i, :, :], higher_percent) 
        
        t = a + (bands[i, :, :] - c) * (b - a) / (d - c) 
        t[t<a] = a 
        t[t>b] = b 
        out[i, :, :] = t 
    return out  

实在不好意思,由于我不做这个项目了,手边也没有数据集,无法运行predict.py,但是我还是可以提供一些解决方法:

  1. 应该是(d - c) 这个项中出现了0值,所以进行除法的时候就会寄掉,可以尝试问问GPT或者NEW BING来看看相关解决方法,这里我个人觉得一个最直接的办法就是将
t = a + (bands[i, :, :] - c) * (b - a) / (d - c) 

改成

t = a + (bands[i, :, :] - c) * (b - a) / (d - c + 1e-9) 

直接增加一个很小的数来避免除以0,但是不知道会不会造成不可预料的后果,你可以先试试,这个方法不行的话,再去问问GPT。

  1. 可以尝试降低numpy版本来进行,我当时进行试验的时候用的是python3.7,conda创建个新环境使用低版本numpy跑一下或许不会报错。
  2. 检查一下数据集是否出错。

@m47777
Copy link
Author

m47777 commented Aug 23, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants