DeepTrial / Retina-VesselNet

A Simple U-net model for Retinal Blood Vessel Segmentation based on tensorflow2
303 stars 76 forks source link

图片补足的时候出现一点小问题 #16

Closed xiewenxin closed 3 years ago

xiewenxin commented 5 years ago
leftover_h = (img_h - config.patch_height) % config.stride_height  # leftover on the h dim
leftover_w = (img_w - config.patch_width) % config.stride_width  # leftover on the w dim
full_imgs=None
if (leftover_h != 0):  #change dimension of img_h
    tmp_imgs = np.zeros((imgs.shape[0],img_h+(config.stride_height-leftover_h),img_w,imgs.shape[3]))
    tmp_imgs[0:imgs.shape[0],0:img_h,0:img_w,0:imgs.shape[3]] = imgs
    full_imgs = tmp_imgs
if (leftover_w != 0):   #change dimension of img_w
    tmp_imgs = np.zeros((full_imgs.shape[0],full_imgs.shape[1],img_w+(config.stride_width - leftover_w),full_imgs.shape[3]))
    tmp_imgs[0:imgs.shape[0],0:imgs.shape[1],0:img_w,0:full_imgs.shape[3]] =imgs
    full_imgs = tmp_imgs
print("new full images shape: \n" +str(full_imgs.shape))
return full_imgs

我的数据集是256*256的,计算下来leftover_h和leftover_w都是0,所以full_imgs直接等于none了。我添加了一个if判断,问题解决了。 if(leftover_h==leftover_w==0): full_imgs=imgs

aakash-saboo commented 5 years ago

This should be the whole function ``

assert (len(imgs.shape) == 4)
img_h = imgs.shape[1]  # height of the full image
img_w = imgs.shape[2]  # width of the full image

leftover_h = (img_h - config.patch_height) % config.stride_height  # leftover on the h dim
leftover_w = (img_w - config.patch_width) % config.stride_width  # leftover on the w dim

full_imgs=None
if (leftover_h != 0 and leftover_w !=0 ):  #change dimension of img_h
    tmp_imgs = np.zeros((imgs.shape[0],img_h+(config.stride_height-leftover_h),img_w,imgs.shape[3]))
    tmp_imgs[0:imgs.shape[0],0:img_h,0:img_w,0:imgs.shape[3]] = imgs
    full_imgs = tmp_imgs

    tmp_imgs = np.zeros((full_imgs.shape[0],full_imgs.shape[1],img_w+(config.stride_width - leftover_w),full_imgs.shape[3]))
    tmp_imgs[0:imgs.shape[0],0:imgs.shape[1],0:img_w,0:full_imgs.shape[3]] =imgs
    full_imgs = tmp_imgs

if (leftover_h == 0 and leftover_w !=0):   #change dimension of img_w
    tmp_imgs = np.zeros((imgs.shape[0],imgs.shape[1],img_w+(config.stride_width - leftover_w),imgs.shape[3]))
    tmp_imgs[0:imgs.shape[0],0:imgs.shape[1],0:img_w,0:imgs.shape[3]] =imgs
    full_imgs = tmp_imgs

if(leftover_h !=0 and leftover_w ==0):
    tmp_imgs = np.zeros((imgs.shape[0],img_h+(config.stride_height-leftover_h),img_w,imgs.shape[3]))
    tmp_imgs[0:imgs.shape[0],0:img_h,0:img_w,0:imgs.shape[3]] = imgs
    full_imgs = tmp_imgs

if(leftover_h==leftover_w==0):
    full_imgs=imgs
print("new full images shape: \n" +str(full_imgs.shape))
return full_imgs
DeepTrial commented 3 years ago

I have update the code. You can find the method on the jupyter notebook. if you still have the problem, open the issue again