Я изучаю Глубокое обучение для улучшения разрешения изображения.
У меня есть вопрос, который нужно задать вам, чтобы найти решение из-за ошибки.
Следующий код должен показать вам весь код, который я хочу разрешить.
- - кодировка: utf-8 - -
patch_size, stride = 40, 20
def gen_patches(file_name):
#### read image ####
img = cv2.imread(file_name, 0) # gray scale
h, w = img.shape
scales = [1, 0.9, 0.8, 0.7]
patches = []
for s in scales:
h_scaled, w_scaled = int(h*s),int(w*s)
img_scaled = cv2.resize(img, (h_scaled,w_scaled), interpolation=cv2.INTER_CUBIC)
#### extract patches ####
for i in range(0, h_scaled-patch_size+1, stride):
for j in range(0, w_scaled-patch_size+1, stride):
x = img_scaled[i:i+patch_size, j:j+patch_size]
return x
if __name__ == '__main__':
### parameters ###
src_dir = '/content/drive/My Drive/CT images/RL500/'
save_dir = '/content/drive/My Drive/'
file_list = glob.glob(src_dir+'*.png') # get name list of all .png files
num_threads = 10
print('Start...')
### initrialize ###
res = []
### generate patches ###
for i in range(0,len(file_list),num_threads):
### use multi-process to speed up ###
p = Pool(num_threads)
patch = p.map(gen_patches,file_list[i:min(i+num_threads,len(file_list))])
###patch = p.map(gen_patches,file_list[i:i+num_threads])###
for x in patch:
res += x
print('Picture '+str(i)+' to '+str(i+num_threads)+' are finished...')
# save to .npy
res = np.array(res, dtype='uint8')
print('Shape of result = ' + str(res.shape))
print('Saving data...')
if not os.path.exists(save_dir):
os.mkdir(save_dir)
np.save(save_dir+'500_patches.npy', res)
print('Done.')
**ValueError: operands could not be broadcast together with shapes (0,) (40,40)**