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 Model Training #42

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
59d4140
updated train.py to reflect changes in cli.py train & trainlaunch
wendywangwwt Jan 31, 2024
2f808f7
updated trainlaunch for single node multi gpu
wendywangwwt Jan 31, 2024
04db7ce
added auto-determination of tile size for data augementation
wendywangwwt Feb 27, 2024
d0033f4
allowed change of subfolder & batchsize when loading data (the former…
wendywangwwt Feb 27, 2024
4aa5194
updated segmentation metrics calculation for deepliifext
wendywangwwt Feb 27, 2024
bcd4d92
added resizeconv, currently inferred from model name / dir
wendywangwwt Mar 5, 2024
c03245b
fixed case when SDG has only 1 input modality
wendywangwwt Mar 7, 2024
a497cf4
added an experimental submodule to facilitate model evaluation and me…
wendywangwwt Mar 7, 2024
20ee9a0
added tv loss
wendywangwwt Mar 20, 2024
507c70c
disabled TV loss
wendywangwwt Apr 4, 2024
08a767c
added experimental model: attention unet
wendywangwwt Apr 4, 2024
aca2060
allowed to change net_gs
wendywangwwt May 15, 2024
7a9c30c
added argument return_seg_intermediate
wendywangwwt May 15, 2024
9aebf56
allowed cli.py inference and test.py to return raw segmentation predi…
wendywangwwt Jun 26, 2024
4cde804
allowed to specify modality-wise generator arch; added validation los…
wendywangwwt Jul 16, 2024
6d9ca56
added schedule-free adamw optimizer
wendywangwwt Jul 25, 2024
952a660
fixed schedule-free optimizer setup (to not use scheduler wrapper); a…
wendywangwwt Jul 31, 2024
351f542
added enable_batchnorm_tracking_stats to be used for validation loss …
wendywangwwt Aug 7, 2024
70a0456
minor fixes for options
wendywangwwt Aug 7, 2024
0051acf
forced cli.py serialize to load models to gpu0 if device=gpu to fix i…
wendywangwwt Aug 7, 2024
f9a8114
updated batchnorm disable and enable functions (missed in the previou…
wendywangwwt Aug 7, 2024
55729a7
merged latest commits from main-update-training
wendywangwwt Aug 7, 2024
a2119cd
removed changes related to stats calculation
wendywangwwt Aug 7, 2024
e437283
removed schedule-free optimizers; allowed --optimizer to use any opti…
wendywangwwt Aug 7, 2024
bcf69bb
resolved merge conflict
wendywangwwt Aug 7, 2024
da6ebc8
added code lines missed during merge
wendywangwwt Aug 8, 2024
661bbb2
changed netg and netgs configuration from list to tuple to avoid pars…
wendywangwwt Aug 8, 2024
cbf8c81
changed to use list in config to standardize
wendywangwwt Aug 13, 2024
7f4a3cf
allowed SDG to use the same postprocess steps as DeepLIIFExt
wendywangwwt Aug 13, 2024
fb75f20
completed validation implementation for deepliifext and sdg, with add…
wendywangwwt Aug 14, 2024
8cc668b
added test cases for training
wendywangwwt Aug 14, 2024
5a277ed
added fake validation set (same as training set :))
wendywangwwt Aug 14, 2024
edab58d
added method to calculate the cell count metrics for the ground truth…
wendywangwwt Aug 14, 2024
38a4f9e
minor fixes: disabled marker image in postprocess in cli.py train val…
wendywangwwt Aug 21, 2024
0af813d
allowed attunet to use custom input output channel size for ext and sdg
wendywangwwt Aug 21, 2024
b18e138
minor fixes: removed print logs
wendywangwwt Aug 21, 2024
7c5cb30
updated train.py and trainlaunch; minor fixes: number of netgs for de…
wendywangwwt Aug 21, 2024
0df24a8
added tests for trainlaunch; changed how the test commands are formed…
wendywangwwt Aug 21, 2024
136540e
cleaned up sdg model
wendywangwwt Aug 21, 2024
95698ae
conditional execution of metrics.json loading
wendywangwwt Aug 21, 2024
60d600e
added changeds in the previous commit to train.py as well
wendywangwwt Aug 22, 2024
0eba7b3
fixed match_suffix function for deepliifext/sdg
wendywangwwt Sep 3, 2024
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
10 changes: 10 additions & 0 deletions Datasets/Sample_Dataset/val/Bladder1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"num_total": 183,
"num_pos": 15,
"num_neg": 168,
"percent_pos": 8.2,
"prob_thresh": 150,
"size_thresh": 30,
"size_thresh_upper": null,
"marker_thresh": null
}
Binary file added Datasets/Sample_Dataset/val/Bladder1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions Datasets/Sample_Dataset/val/Lung1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"num_total": 60,
"num_pos": 11,
"num_neg": 49,
"percent_pos": 18.3,
"prob_thresh": 150,
"size_thresh": 78,
"size_thresh_upper": null,
"marker_thresh": null
}
Binary file added Datasets/Sample_Dataset/val/Lung1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions Datasets/Sample_Dataset/val/metrics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"Lung1": {
"num_total": 60,
"num_pos": 11,
"num_neg": 49,
"percent_pos": 18.3,
"prob_thresh": 150,
"size_thresh": 78,
"size_thresh_upper": null,
"marker_thresh": null
},
"Bladder1": {
"num_total": 183,
"num_pos": 15,
"num_neg": 168,
"percent_pos": 8.2,
"prob_thresh": 150,
"size_thresh": 30,
"size_thresh_upper": null,
"marker_thresh": null
}
}
18 changes: 10 additions & 8 deletions Image_Processing/Augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@


class Augmentation:
def __init__(self, images):
def __init__(self, images, tile_size=512):
self.images = images
self.shape = self.images[list(self.images.keys())[0]].shape
self.rotation_angle = np.random.choice([0, 90, 180, 270], 1)[0]
# self.zoom_value = random.randint(0, 5)
self.alpha_affine = 0.1
self.tile_size = tile_size

def pipeline(self):
"""
Expand All @@ -30,12 +31,13 @@ def zoom(self):
:return:
"""
new_size = random.randint(int(self.shape[0] * 0.75), self.shape[0])
assert self.shape[1] - new_size >= 0, f'self.shape[1] - new_size ({self.shape[1]} - {new_size})should not be negative'
start_point = (random.randint(0, self.shape[0] - new_size), random.randint(0, self.shape[1] - new_size))
for key in self.images.keys():
try:
self.images[key] = cv2.resize(self.images[key][start_point[0]: start_point[0] + new_size, start_point[1]: start_point[1] + new_size], (512, 512))
except:
print(key + ' not available')
self.images[key] = cv2.resize(self.images[key][start_point[0]: start_point[0] + new_size, start_point[1]: start_point[1] + new_size], (self.tile_size, self.tile_size))
except Exception as e:
print(e)

def rotate(self):
"""
Expand All @@ -47,8 +49,8 @@ def rotate(self):
for key in self.images.keys():
try:
self.images[key] = ndimage.rotate(self.images[key], self.rotation_angle, reshape=False)
except:
print(key + ' not available')
except Exception as e:
print(e)

def elastic_transform(self, random_state=None):
"""
Expand Down Expand Up @@ -78,5 +80,5 @@ def elastic_transform(self, random_state=None):
for key in self.images.keys():
try:
self.images[key] = cv2.warpAffine(self.images[key], M, shape_size[::-1], borderMode=cv2.BORDER_REFLECT_101)
except:
print(key + ' not available')
except Exception as e:
print(e)
17 changes: 13 additions & 4 deletions Image_Processing/Image_Processing_Helper_Functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def create_training_testing_dataset_from_given_directory(input_dir, output_dir,
cv2.imwrite(os.path.join(all_dirs[i], filename), all_images[filename])


def augment_set(input_dir, output_dir, aug_no=9, modality_types=['hematoxylin', 'CD3', 'PanCK'], tile_size=512):
def augment_set(input_dir, output_dir, aug_no=9, modality_types=['hematoxylin', 'CD3', 'PanCK']):
"""
This function augments a co-aligned dataset.

Expand All @@ -105,20 +105,29 @@ def augment_set(input_dir, output_dir, aug_no=9, modality_types=['hematoxylin',
"""
if not os.path.exists(output_dir):
os.makedirs(output_dir)
images = os.listdir(input_dir)
for img in images:
images_original = os.listdir(input_dir)
print(f'{len(images_original)} images found')

count = 0
for i,img in enumerate(images_original):
augmented = 0
while augmented < aug_no:
images = {}
image = cv2.imread(os.path.join(input_dir, img))
if i == 0:
tile_size = image.shape[0]
assert image.shape[1] >= len(modality_types) * tile_size, f'image width ({image.shape[1]}) is not enough for {len(modality_types)} modalities with tile size {tile_size}'
for i in range(0, len(modality_types)):
images[modality_types[i]] = image[:, i * tile_size: (i + 1) * tile_size]
new_images = images.copy()
aug = Augmentation(new_images)
aug = Augmentation(new_images, tile_size)
aug.pipeline()
cv2.imwrite(os.path.join(output_dir, img.replace('.png', '_' + str(augmented) + '.png')),
np.concatenate(list(new_images.values()), 1))
augmented += 1
count += 1
if count % 10 == 0 or count == len(images_original):
print(f'Done {count}/{len(images_original)}')


def augment_created_dataset(input_dir, output_dir, aug_no=9, modality_types=['hematoxylin', 'CD3', 'PanCK'], tile_size=512):
Expand Down
Loading