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

updated code #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*~
*.pyc
.DS_Store
DRIVE_datasets_training_testing
DRIVE_datasets_training_testing
Binary file added DRIVE/test/1st_manual/01_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/02_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/03_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/04_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/05_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/06_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/07_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/08_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/09_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/10_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/11_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/12_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/13_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/14_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/15_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/16_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/17_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/18_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/19_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/20_manual1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/jpg format/vessel(1).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/jpg format/vessel(10).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/jpg format/vessel(2).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/jpg format/vessel(3).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/jpg format/vessel(4).jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DRIVE/test/1st_manual/jpg format/vessel(5).jpg
Binary file added DRIVE/test/1st_manual/jpg format/vessel(6).jpg
Binary file added DRIVE/test/1st_manual/jpg format/vessel(7).jpg
Binary file added DRIVE/test/1st_manual/jpg format/vessel(8).jpg
Binary file added DRIVE/test/1st_manual/jpg format/vessel(9).jpg
Binary file added DRIVE/test/2nd_manual/05_manual2.gif
Binary file added DRIVE/test/2nd_manual/06_manual2.gif
Binary file added DRIVE/test/2nd_manual/07_manual2.gif
Binary file added DRIVE/test/2nd_manual/08_manual2.gif
Binary file added DRIVE/test/2nd_manual/09_manual2.gif
Binary file added DRIVE/test/2nd_manual/10_manual2.gif
Binary file added DRIVE/test/2nd_manual/11_manual2.gif
Binary file added DRIVE/test/2nd_manual/12_manual2.gif
Binary file added DRIVE/test/2nd_manual/13_manual2.gif
Binary file added DRIVE/test/2nd_manual/15_manual2.gif
Binary file added DRIVE/test/2nd_manual/16_manual2.gif
Binary file added DRIVE/test/2nd_manual/17_manual2.gif
Binary file added DRIVE/test/2nd_manual/18_manual2.gif
Binary file added DRIVE/test/2nd_manual/19_manual2.gif
Binary file added DRIVE/test/2nd_manual/20_manual2.gif
Binary file added DRIVE/test/2nd_manual/vessel(1).gif
Binary file added DRIVE/test/2nd_manual/vessel(14).gif
Binary file added DRIVE/test/2nd_manual/vessel(2).gif
Binary file added DRIVE/test/2nd_manual/vessel(3).gif
Binary file added DRIVE/test/2nd_manual/vessel(4).gif
Binary file added DRIVE/test/images/01_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/02_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/03_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/04_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/05_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/06_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/07_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/08_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/09_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/10_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/11_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/12_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/13_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/14_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/15_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/16_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/17_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/18_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/19_test.tif
Binary file not shown.
Binary file added DRIVE/test/images/20_test.tif
Binary file not shown.
Binary file added DRIVE/test/mask/01_test_mask.gif
Binary file added DRIVE/test/mask/02_test_mask.gif
Binary file added DRIVE/test/mask/03_test_mask.gif
Binary file added DRIVE/test/mask/04_test_mask.gif
Binary file added DRIVE/test/mask/05_test_mask.gif
Binary file added DRIVE/test/mask/06_test_mask.gif
Binary file added DRIVE/test/mask/07_test_mask.gif
Binary file added DRIVE/test/mask/08_test_mask.gif
Binary file added DRIVE/test/mask/09_test_mask.gif
Binary file added DRIVE/test/mask/10_test_mask.gif
Binary file added DRIVE/test/mask/11_test_mask.gif
Binary file added DRIVE/test/mask/12_test_mask.gif
Binary file added DRIVE/test/mask/13_test_mask.gif
Binary file added DRIVE/test/mask/14_test_mask.gif
Binary file added DRIVE/test/mask/15_test_mask.gif
Binary file added DRIVE/test/mask/16_test_mask.gif
Binary file added DRIVE/test/mask/17_test_mask.gif
Binary file added DRIVE/test/mask/18_test_mask.gif
Binary file added DRIVE/test/mask/19_test_mask.gif
Binary file added DRIVE/test/mask/20_test_mask.gif
Binary file added DRIVE/training/1st_manual/21_manual1.gif
Binary file added DRIVE/training/1st_manual/22_manual1.gif
Binary file added DRIVE/training/1st_manual/23_manual1.gif
Binary file added DRIVE/training/1st_manual/24_manual1.gif
Binary file added DRIVE/training/1st_manual/25_manual1.gif
Binary file added DRIVE/training/1st_manual/26_manual1.gif
Binary file added DRIVE/training/1st_manual/27_manual1.gif
Binary file added DRIVE/training/1st_manual/28_manual1.gif
Binary file added DRIVE/training/1st_manual/29_manual1.gif
Binary file added DRIVE/training/1st_manual/30_manual1.gif
Binary file added DRIVE/training/1st_manual/31_manual1.gif
Binary file added DRIVE/training/1st_manual/32_manual1.gif
Binary file added DRIVE/training/1st_manual/33_manual1.gif
Binary file added DRIVE/training/1st_manual/34_manual1.gif
Binary file added DRIVE/training/1st_manual/35_manual1.gif
Binary file added DRIVE/training/1st_manual/36_manual1.gif
Binary file added DRIVE/training/1st_manual/37_manual1.gif
Binary file added DRIVE/training/1st_manual/38_manual1.gif
Binary file added DRIVE/training/1st_manual/39_manual1.gif
Binary file added DRIVE/training/1st_manual/40_manual1.gif
Binary file added DRIVE/training/images/21_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/22_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/23_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/24_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/25_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/26_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/27_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/28_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/29_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/30_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/31_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/32_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/33_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/34_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/35_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/36_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/37_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/38_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/39_training.tif
Binary file not shown.
Binary file added DRIVE/training/images/40_training.tif
Binary file not shown.
Binary file added DRIVE/training/mask/21_training_mask.gif
Binary file added DRIVE/training/mask/22_training_mask.gif
Binary file added DRIVE/training/mask/23_training_mask.gif
Binary file added DRIVE/training/mask/24_training_mask.gif
Binary file added DRIVE/training/mask/25_training_mask.gif
Binary file added DRIVE/training/mask/26_training_mask.gif
Binary file added DRIVE/training/mask/27_training_mask.gif
Binary file added DRIVE/training/mask/28_training_mask.gif
Binary file added DRIVE/training/mask/29_training_mask.gif
Binary file added DRIVE/training/mask/30_training_mask.gif
Binary file added DRIVE/training/mask/31_training_mask.gif
Binary file added DRIVE/training/mask/32_training_mask.gif
Binary file added DRIVE/training/mask/33_training_mask.gif
Binary file added DRIVE/training/mask/34_training_mask.gif
Binary file added DRIVE/training/mask/35_training_mask.gif
Binary file added DRIVE/training/mask/36_training_mask.gif
Binary file added DRIVE/training/mask/37_training_mask.gif
Binary file added DRIVE/training/mask/38_training_mask.gif
Binary file added DRIVE/training/mask/39_training_mask.gif
Binary file added DRIVE/training/mask/40_training_mask.gif
8 changes: 8 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ The following dependencies are needed:
- ConfigParser >=3.5.0b2
- scikit-learn >= 0.17.1

Version used
- python3 = 3.9.13
- numpy = 1.19.5
- PIL =8.2.0
- opencv =4.5.2
- h5py =3.1.0
- configparser =3.10.6
- scikit-learn = 0.24.2

Also, you will need the DRIVE database, which can be freely downloaded as explained in the next section.

Expand Down
92 changes: 46 additions & 46 deletions lib/extract_patches.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import random
import ConfigParser
#import ConfigParser

from help_functions import load_hdf5
from help_functions import visualize
Expand Down Expand Up @@ -34,18 +34,18 @@ def get_data_training(DRIVE_train_imgs_original,
#check masks are within 0-1
assert(np.min(train_masks)==0 and np.max(train_masks)==1)

print "\ntrain images/masks shape:"
print train_imgs.shape
print "train images range (min-max): " +str(np.min(train_imgs)) +' - '+str(np.max(train_imgs))
print "train masks are within 0-1\n"
print ("\ntrain images/masks shape:")
print (train_imgs.shape)
print ("train images range (min-max): " +str(np.min(train_imgs)) +' - '+str(np.max(train_imgs)))
print ("train masks are within 0-1\n")

#extract the TRAINING patches from the full images
patches_imgs_train, patches_masks_train = extract_random(train_imgs,train_masks,patch_height,patch_width,N_subimgs,inside_FOV)
data_consistency_check(patches_imgs_train, patches_masks_train)

print "\ntrain PATCHES images/masks shape:"
print patches_imgs_train.shape
print "train PATCHES images range (min-max): " +str(np.min(patches_imgs_train)) +' - '+str(np.max(patches_imgs_train))
print ("\ntrain PATCHES images/masks shape:")
print (patches_imgs_train.shape)
print ("train PATCHES images range (min-max): " +str(np.min(patches_imgs_train)) +' - '+str(np.max(patches_imgs_train)))

return patches_imgs_train, patches_masks_train#, patches_imgs_test, patches_masks_test

Expand All @@ -70,19 +70,19 @@ def get_data_testing(DRIVE_test_imgs_original, DRIVE_test_groudTruth, Imgs_to_te
#check masks are within 0-1
assert(np.max(test_masks)==1 and np.min(test_masks)==0)

print "\ntest images/masks shape:"
print test_imgs.shape
print "test images range (min-max): " +str(np.min(test_imgs)) +' - '+str(np.max(test_imgs))
print "test masks are within 0-1\n"
print ("\ntest images/masks shape:")
print (test_imgs.shape)
print ("test images range (min-max): " +str(np.min(test_imgs)) +' - '+str(np.max(test_imgs)))
print ("test masks are within 0-1\n")

#extract the TEST patches from the full images
patches_imgs_test = extract_ordered(test_imgs,patch_height,patch_width)
patches_masks_test = extract_ordered(test_masks,patch_height,patch_width)
data_consistency_check(patches_imgs_test, patches_masks_test)

print "\ntest PATCHES images/masks shape:"
print patches_imgs_test.shape
print "test PATCHES images range (min-max): " +str(np.min(patches_imgs_test)) +' - '+str(np.max(patches_imgs_test))
print ("\ntest PATCHES images/masks shape:")
print (patches_imgs_test.shape)
print ("test PATCHES images range (min-max): " +str(np.min(patches_imgs_test)) +' - '+str(np.max(patches_imgs_test)))

return patches_imgs_test, patches_masks_test

Expand All @@ -106,19 +106,19 @@ def get_data_testing_overlap(DRIVE_test_imgs_original, DRIVE_test_groudTruth, Im
#check masks are within 0-1
assert(np.max(test_masks)==1 and np.min(test_masks)==0)

print "\ntest images shape:"
print test_imgs.shape
print "\ntest mask shape:"
print test_masks.shape
print "test images range (min-max): " +str(np.min(test_imgs)) +' - '+str(np.max(test_imgs))
print "test masks are within 0-1\n"
print ("\ntest images shape:")
print (test_imgs.shape)
print ("\ntest mask shape:")
print (test_masks.shape)
print ("test images range (min-max): " +str(np.min(test_imgs)) +' - '+str(np.max(test_imgs)))
print ("test masks are within 0-1\n")

#extract the TEST patches from the full images
patches_imgs_test = extract_ordered_overlap(test_imgs,patch_height,patch_width,stride_height,stride_width)

print "\ntest PATCHES images shape:"
print patches_imgs_test.shape
print "test PATCHES images range (min-max): " +str(np.min(patches_imgs_test)) +' - '+str(np.max(patches_imgs_test))
print ("\ntest PATCHES images shape:")
print (patches_imgs_test.shape)
print ("test PATCHES images range (min-max): " +str(np.min(patches_imgs_test)) +' - '+str(np.max(patches_imgs_test)))

return patches_imgs_test, test_imgs.shape[2], test_imgs.shape[3], test_masks

Expand All @@ -137,7 +137,7 @@ def data_consistency_check(imgs,masks):
# -- Inside OR in full image
def extract_random(full_imgs,full_masks, patch_h,patch_w, N_patches, inside=True):
if (N_patches%full_imgs.shape[0] != 0):
print "N_patches: plase enter a multiple of 20"
print ("N_patches: plase enter a multiple of 20")
exit()
assert (len(full_imgs.shape)==4 and len(full_masks.shape)==4) #4D arrays
assert (full_imgs.shape[1]==1 or full_imgs.shape[1]==3) #check the channel is 1 or 3
Expand All @@ -149,7 +149,7 @@ def extract_random(full_imgs,full_masks, patch_h,patch_w, N_patches, inside=True
img_w = full_imgs.shape[3] #width of the full image
# (0,0) in the center of the image
patch_per_img = int(N_patches/full_imgs.shape[0]) #N_patches equally divided in the full images
print "patches per full image: " +str(patch_per_img)
print ("patches per full image: " +str(patch_per_img))
iter_tot = 0 #iter over the total numbe rof patches (N_patches)
for i in range(full_imgs.shape[0]): #loop over the full images
k=0
Expand Down Expand Up @@ -191,11 +191,11 @@ def extract_ordered(full_imgs, patch_h, patch_w):
img_w = full_imgs.shape[3] #width of the full image
N_patches_h = int(img_h/patch_h) #round to lowest int
if (img_h%patch_h != 0):
print "warning: " +str(N_patches_h) +" patches in height, with about " +str(img_h%patch_h) +" pixels left over"
print ("warning: " +str(N_patches_h) +" patches in height, with about " +str(img_h%patch_h) +" pixels left over")
N_patches_w = int(img_w/patch_w) #round to lowest int
if (img_h%patch_h != 0):
print "warning: " +str(N_patches_w) +" patches in width, with about " +str(img_w%patch_w) +" pixels left over"
print "number of patches per image: " +str(N_patches_h*N_patches_w)
print ("warning: " +str(N_patches_w) +" patches in width, with about " +str(img_w%patch_w) +" pixels left over")
print ("number of patches per image: " +str(N_patches_h*N_patches_w))
N_patches_tot = (N_patches_h*N_patches_w)*full_imgs.shape[0]
patches = np.empty((N_patches_tot,full_imgs.shape[1],patch_h,patch_w))

Expand All @@ -218,22 +218,22 @@ def paint_border_overlap(full_imgs, patch_h, patch_w, stride_h, stride_w):
leftover_h = (img_h-patch_h)%stride_h #leftover on the h dim
leftover_w = (img_w-patch_w)%stride_w #leftover on the w dim
if (leftover_h != 0): #change dimension of img_h
print "\nthe side H is not compatible with the selected stride of " +str(stride_h)
print "img_h " +str(img_h) + ", patch_h " +str(patch_h) + ", stride_h " +str(stride_h)
print "(img_h - patch_h) MOD stride_h: " +str(leftover_h)
print "So the H dim will be padded with additional " +str(stride_h - leftover_h) + " pixels"
print ("\nthe side H is not compatible with the selected stride of " +str(stride_h))
print ("img_h " +str(img_h) + ", patch_h " +str(patch_h) + ", stride_h " +str(stride_h))
print ("(img_h - patch_h) MOD stride_h: " +str(leftover_h))
print ("So the H dim will be padded with additional " +str(stride_h - leftover_h) + " pixels")
tmp_full_imgs = np.zeros((full_imgs.shape[0],full_imgs.shape[1],img_h+(stride_h-leftover_h),img_w))
tmp_full_imgs[0:full_imgs.shape[0],0:full_imgs.shape[1],0:img_h,0:img_w] = full_imgs
full_imgs = tmp_full_imgs
if (leftover_w != 0): #change dimension of img_w
print "the side W is not compatible with the selected stride of " +str(stride_w)
print "img_w " +str(img_w) + ", patch_w " +str(patch_w) + ", stride_w " +str(stride_w)
print "(img_w - patch_w) MOD stride_w: " +str(leftover_w)
print "So the W dim will be padded with additional " +str(stride_w - leftover_w) + " pixels"
print ("the side W is not compatible with the selected stride of " +str(stride_w))
print ("img_w " +str(img_w) + ", patch_w " +str(patch_w) + ", stride_w " +str(stride_w))
print ("(img_w - patch_w) MOD stride_w: " +str(leftover_w))
print ("So the W dim will be padded with additional " +str(stride_w - leftover_w) + " pixels")
tmp_full_imgs = np.zeros((full_imgs.shape[0],full_imgs.shape[1],full_imgs.shape[2],img_w+(stride_w - leftover_w)))
tmp_full_imgs[0:full_imgs.shape[0],0:full_imgs.shape[1],0:full_imgs.shape[2],0:img_w] = full_imgs
full_imgs = tmp_full_imgs
print "new full images shape: \n" +str(full_imgs.shape)
print ("new full images shape: \n" +str(full_imgs.shape))
return full_imgs

#Divide all the full_imgs in pacthes
Expand All @@ -245,9 +245,9 @@ def extract_ordered_overlap(full_imgs, patch_h, patch_w,stride_h,stride_w):
assert ((img_h-patch_h)%stride_h==0 and (img_w-patch_w)%stride_w==0)
N_patches_img = ((img_h-patch_h)//stride_h+1)*((img_w-patch_w)//stride_w+1) #// --> division between integers
N_patches_tot = N_patches_img*full_imgs.shape[0]
print "Number of patches on h : " +str(((img_h-patch_h)//stride_h+1))
print "Number of patches on w : " +str(((img_w-patch_w)//stride_w+1))
print "number of patches per image: " +str(N_patches_img) +", totally for this dataset: " +str(N_patches_tot)
print ("Number of patches on h : " +str(((img_h-patch_h)//stride_h+1)))
print ("Number of patches on w : " +str(((img_w-patch_w)//stride_w+1)))
print ("number of patches per image: " +str(N_patches_img) +", totally for this dataset: " +str(N_patches_tot))
patches = np.empty((N_patches_tot,full_imgs.shape[1],patch_h,patch_w))
iter_tot = 0 #iter over the total number of patches (N_patches)
for i in range(full_imgs.shape[0]): #loop over the full images
Expand All @@ -268,12 +268,12 @@ def recompone_overlap(preds, img_h, img_w, stride_h, stride_w):
N_patches_h = (img_h-patch_h)//stride_h+1
N_patches_w = (img_w-patch_w)//stride_w+1
N_patches_img = N_patches_h * N_patches_w
print "N_patches_h: " +str(N_patches_h)
print "N_patches_w: " +str(N_patches_w)
print "N_patches_img: " +str(N_patches_img)
print ("N_patches_h: " +str(N_patches_h))
print ("N_patches_w: " +str(N_patches_w))
print ("N_patches_img: " +str(N_patches_img))
assert (preds.shape[0]%N_patches_img==0)
N_full_imgs = preds.shape[0]//N_patches_img
print "According to the dimension inserted, there are " +str(N_full_imgs) +" full images (of " +str(img_h)+"x" +str(img_w) +" each)"
print ("According to the dimension inserted, there are " +str(N_full_imgs) +" full images (of " +str(img_h)+"x" +str(img_w) +" each)")
full_prob = np.zeros((N_full_imgs,preds.shape[1],img_h,img_w)) #itialize to zero mega array with sum of Probabilities
full_sum = np.zeros((N_full_imgs,preds.shape[1],img_h,img_w))

Expand All @@ -287,7 +287,7 @@ def recompone_overlap(preds, img_h, img_w, stride_h, stride_w):
assert(k==preds.shape[0])
assert(np.min(full_sum)>=1.0) #at least one
final_avg = full_prob/full_sum
print final_avg.shape
print (final_avg.shape)
assert(np.max(final_avg)<=1.0) #max value for a pixel is 1.0
assert(np.min(final_avg)>=0.0) #min value for a pixel is 0.0
return final_avg
Expand Down
2 changes: 1 addition & 1 deletion lib/help_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def pred_to_imgs(pred, patch_height, patch_width, mode="original"):
else:
pred_images[i,pix]=0
else:
print "mode " +str(mode) +" not recognized, it can be 'original' or 'threshold'"
print ("mode " +str(mode) +" not recognized, it can be 'original' or 'threshold'")
exit()
pred_images = np.reshape(pred_images,(pred_images.shape[0],1, patch_height, patch_width))
return pred_images
18 changes: 9 additions & 9 deletions prepare_datasets_DRIVE.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def get_datasets(imgs_dir,groundTruth_dir,borderMasks_dir,train_test="null"):
for path, subdirs, files in os.walk(imgs_dir): #list all files, directories in the path
for i in range(len(files)):
#original
print "original image: " +files[i]
print ("original image: " +files[i])
img = Image.open(imgs_dir+files[i])
imgs[i] = np.asarray(img)
#corresponding ground truth
groundTruth_name = files[i][0:2] + "_manual1.gif"
print "ground truth name: " + groundTruth_name
print ("ground truth name: " + groundTruth_name)
g_truth = Image.open(groundTruth_dir + groundTruth_name)
groundTruth[i] = np.asarray(g_truth)
#corresponding border masks
Expand All @@ -55,17 +55,17 @@ def get_datasets(imgs_dir,groundTruth_dir,borderMasks_dir,train_test="null"):
elif train_test=="test":
border_masks_name = files[i][0:2] + "_test_mask.gif"
else:
print "specify if train or test!!"
print ("specify if train or test!!")
exit()
print "border masks name: " + border_masks_name
print ("border masks name: " + border_masks_name)
b_mask = Image.open(borderMasks_dir + border_masks_name)
border_masks[i] = np.asarray(b_mask)

print "imgs max: " +str(np.max(imgs))
print "imgs min: " +str(np.min(imgs))
print ("imgs max: " +str(np.max(imgs)))
print ("imgs min: " +str(np.min(imgs)))
assert(np.max(groundTruth)==255 and np.max(border_masks)==255)
assert(np.min(groundTruth)==0 and np.min(border_masks)==0)
print "ground truth and border masks are correctly withih pixel value range 0-255 (black-white)"
print ("ground truth and border masks are correctly withih pixel value range 0-255 (black-white)")
#reshaping for my standard tensors
imgs = np.transpose(imgs,(0,3,1,2))
assert(imgs.shape == (Nimgs,channels,height,width))
Expand All @@ -79,14 +79,14 @@ def get_datasets(imgs_dir,groundTruth_dir,borderMasks_dir,train_test="null"):
os.makedirs(dataset_path)
#getting the training datasets
imgs_train, groundTruth_train, border_masks_train = get_datasets(original_imgs_train,groundTruth_imgs_train,borderMasks_imgs_train,"train")
print "saving train datasets"
print ("saving train datasets")
write_hdf5(imgs_train, dataset_path + "DRIVE_dataset_imgs_train.hdf5")
write_hdf5(groundTruth_train, dataset_path + "DRIVE_dataset_groundTruth_train.hdf5")
write_hdf5(border_masks_train,dataset_path + "DRIVE_dataset_borderMasks_train.hdf5")

#getting the testing datasets
imgs_test, groundTruth_test, border_masks_test = get_datasets(original_imgs_test,groundTruth_imgs_test,borderMasks_imgs_test,"test")
print "saving test datasets"
print ("saving test datasets")
write_hdf5(imgs_test,dataset_path + "DRIVE_dataset_imgs_test.hdf5")
write_hdf5(groundTruth_test, dataset_path + "DRIVE_dataset_groundTruth_test.hdf5")
write_hdf5(border_masks_test,dataset_path + "DRIVE_dataset_borderMasks_test.hdf5")
10 changes: 5 additions & 5 deletions run_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
##################################################

import os, sys
import ConfigParser
import configparser


#config file to read from
config = ConfigParser.RawConfigParser()
config = configparser.RawConfigParser()
config.readfp(open(r'./configuration.txt'))
#===========================================
#name of the experiment!!
Expand All @@ -20,7 +20,7 @@

#create a folder for the results if not existing already
result_dir = name_experiment
print "\n1. Create directory for the results (if not already existing)"
print ("\n1. Create directory for the results (if not already existing)")
if os.path.exists(result_dir):
pass
elif sys.platform=='win32':
Expand All @@ -31,8 +31,8 @@

# finally run the prediction
if nohup:
print "\n2. Run the prediction on GPU with nohup"
print ("\n2. Run the prediction on GPU with nohup")
os.system(run_GPU +' nohup python -u ./src/retinaNN_predict.py > ' +'./'+name_experiment+'/'+name_experiment+'_prediction.nohup')
else:
print "\n2. Run the prediction on GPU (no nohup)"
print ("\n2. Run the prediction on GPU (no nohup)")
os.system(run_GPU +' python ./src/retinaNN_predict.py')
20 changes: 10 additions & 10 deletions run_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
##################################################

import os, sys
import ConfigParser
import configparser


#config file to read from
config = ConfigParser.RawConfigParser()
config.readfp(open(r'./configuration.txt'))
config = configparser.RawConfigParser()
config.read_file(open(r'./configuration.txt'))
#===========================================
#name of the experiment
name_experiment = config.get('experiment name', 'name')
Expand All @@ -20,26 +20,26 @@

#create a folder for the results
result_dir = name_experiment
print "\n1. Create directory for the results (if not already existing)"
print ("\n1. Create directory for the results (if not already existing)")
if os.path.exists(result_dir):
print "Dir already existing"
print ("Dir already existing")
elif sys.platform=='win32':
os.system('mkdir ' + result_dir)
else:
os.system('mkdir -p ' +result_dir)

print "copy the configuration file in the results folder"
print ("copy the configuration file in the results folder")
if sys.platform=='win32':
os.system('copy configuration.txt .\\' +name_experiment+'\\'+name_experiment+'_configuration.txt')
else:
os.system('cp configuration.txt ./' +name_experiment+'/'+name_experiment+'_configuration.txt')

# run the experiment
if nohup:
print "\n2. Run the training on GPU with nohup"
os.system(run_GPU +' nohup python -u ./src/retinaNN_training.py > ' +'./'+name_experiment+'/'+name_experiment+'_training.nohup')
print ("\n2. Run the training on GPU with nohup")
os.system(run_GPU +' start /min python3 -u ./src/retinaNN_training.py > ' +'./'+name_experiment+'/'+name_experiment+'_training.nohup')
else:
print "\n2. Run the training on GPU (no nohup)"
os.system(run_GPU +' python ./src/retinaNN_training.py')
print ("\n2. Run the training on GPU (no nohup)")
os.system(run_GPU +' python3 ./src/retinaNN_training.py')

#Prediction/testing is run with a different script
Loading