lindawangg / COVID-Net

COVID-Net Open Source Initiative
Other
1.15k stars 480 forks source link

error no file of SARS-10.1148rg.242035193-g04mr34g0-Fig8b-day5.jpeg on datasetCovidx_v4 #89

Closed hendrikTpl closed 4 years ago

hendrikTpl commented 4 years ago

I have followed the step to creating data for training and testing as mentioned in file create_COVIDx.ipynb, however, it seems like the file does not exist

when I run this script

`# add covid-chestxray-dataset, figure1 and actualmed into COVIDx dataset # since these datasets don't have test dataset, split into train/test by patientid # for covid-chestxray-dataset: # patient 8 is used as non-COVID19 viral test # patient 31 is used as bacterial test # patients 19, 20, 36, 42, 86 are used as COVID-19 viral test # for figure 1: # patients 24, 25, 27, 29, 30, 32, 33, 36, 37, 38

ds_imgpath = {'cohen': cohen_imgpath, 'fig1': fig1_imgpath, 'actmed': actmed_imgpath, 'sirm': sirm_imgpath}

for key in filename_label.keys(): arr = np.array(filename_label[key]) if arr.size == 0: continue

split by patients

# num_diff_patients = len(np.unique(arr[:,0]))
# num_test = max(1, round(split*num_diff_patients))
# select num_test number of random patients
# random.sample(list(arr[:,0]), num_test)
if key == 'pneumonia':
    test_patients = ['8', '31']
elif key == 'COVID-19':
    test_patients = ['19', '20', '36', '42', '86', 
                     '94', '97', '117', '132', 
                     '138', '144', '150', '163', '169', '174', '175', '179', '190', '191'
                     'COVID-00024', 'COVID-00025', 'COVID-00026', 'COVID-00027', 'COVID-00029',
                     'COVID-00030', 'COVID-00032', 'COVID-00033', 'COVID-00035', 'COVID-00036',
                     'COVID-00037', 'COVID-00038',
                     'ANON24', 'ANON45', 'ANON126', 'ANON106', 'ANON67',
                     'ANON153', 'ANON135', 'ANON44', 'ANON29', 'ANON201', 
                     'ANON191', 'ANON234', 'ANON110', 'ANON112', 'ANON73', 
                     'ANON220', 'ANON189', 'ANON30', 'ANON53', 'ANON46',
                     'ANON218', 'ANON240', 'ANON100', 'ANON237', 'ANON158',
                     'ANON174', 'ANON19', 'ANON195',
                     'COVID-19(119)', 'COVID-19(87)', 'COVID-19(70)', 'COVID-19(94)', 
                     'COVID-19(215)', 'COVID-19(77)', 'COVID-19(213)', 'COVID-19(81)', 
                     'COVID-19(216)', 'COVID-19(72)', 'COVID-19(106)', 'COVID-19(131)', 
                     'COVID-19(107)', 'COVID-19(116)', 'COVID-19(95)', 'COVID-19(214)', 
                     'COVID-19(129)']
else: 
    test_patients = []
print('Key: ', key)
print('Test patients: ', test_patients)
# go through all the patients

for patient in arr:
    if patient[0] not in patient_imgpath:
        patient_imgpath[patient[0]] = [patient[1]]
    else:
        if patient[1] not in patient_imgpath[patient[0]]:
            patient_imgpath[patient[0]].append(patient[1])
        else:
            continue  # skip since image has already been written
    if patient[0] in test_patients:
        if patient[3] == 'sirm':
            image = cv2.imread(os.path.join(ds_imgpath[patient[3]], patient[1]))
            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
            patient[1] = patient[1].replace(' ', '')
            cv2.imwrite(os.path.join(savepath, 'test', patient[1]), gray)
        else:
            copyfile(os.path.join(ds_imgpath[patient[3]], patient[1]), os.path.join(savepath, 'test', patient[1]))
        test.append(patient)
        test_count[patient[2]] += 1
    else:
        if patient[3] == 'sirm':
            image = cv2.imread(os.path.join(ds_imgpath[patient[3]], patient[1]))
            gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
            patient[1] = patient[1].replace(' ', '')
            cv2.imwrite(os.path.join(savepath, 'train', patient[1]), gray)
        else:
            copyfile(os.path.join(ds_imgpath[patient[3]], patient[1]), os.path.join(savepath, 'train', patient[1]))
        train.append(patient)
        train_count[patient[2]] += 1

print('test count: ', test_count) print('train count: ', train_count)` here the error message

FileNotFoundError: [Errno 2] No such file or directory: 'data/train/SARS-10.1148rg.242035193-g04mr34g0-Fig8b-day5.jpeg'


FileNotFoundError Traceback (most recent call last)

in 70 cv2.imwrite(os.path.join(savepath, 'train', patient[1]), gray) 71 else: ---> 72 copyfile(os.path.join(ds_imgpath[patient[3]], patient[1]), os.path.join(savepath, 'train', patient[1])) 73 train.append(patient) 74 train_count[patient[2]] += 1 ~/anaconda3/envs/covid/lib/python3.6/shutil.py in copyfile(src, dst, follow_symlinks) 119 else: 120 with open(src, 'rb') as fsrc: --> 121 with open(dst, 'wb') as fdst: 122 copyfileobj(fsrc, fdst) 123 return dst FileNotFoundError: [Errno 2] No such file or directory: 'data/train/SARS-10.1148rg.242035193-g04mr34g0-Fig8b-day5.jpeg'
hendrikTpl commented 4 years ago

close

fer2k commented 4 years ago

hi, could you solve you problem? i have the same error, what did you do to solve it?