pytorch報錯:ValueError: num_samples should be a positive integer value, but got num_samples=0

最近在訓練網絡的時候,報錯ValueError: num_samples should be a positive integer value, but got num_samples=0。

經過調試發現,這是在dataloader環節出現了問題。在數據讀取時一個判斷寫的越界了,如下所示

def make_dataset(dir, opt):
    images = []
    assert os.path.isdir(dir), '%s is not a valid directory' % dir
    fileList = sorted(os.walk(dir))    
    for root, _, fnames in fileList:
        for fname in fnames:
            if is_image_file(fname):
                path = os.path.join(root, fname)
                if ((opt.phase=='test') or (opt.phase=='train') and min(Image.open(path).size) >= 512):
                    images.append(path)        
    return images

當加載的圖片小於512就會報錯,把判斷改小就解決了bug。

所以出現這個報錯,就說明是訓練數據沒有加載成功,檢查數據加載的相關程序。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章