Skip to content

Commit

Permalink
new files added
Browse files Browse the repository at this point in the history
  • Loading branch information
YousefMetwally committed Jul 31, 2024
1 parent 6d2973a commit 3568e80
Show file tree
Hide file tree
Showing 13 changed files with 2,027 additions and 13 deletions.
Empty file added VAE.ipynb
Empty file.
Empty file added noskip32.ipynb
Empty file.
Empty file added optuna.ipynb
Empty file.
40 changes: 40 additions & 0 deletions optuna_study.db
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{"op_code": 0, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "study_name": "3D_UNet_Optimization", "directions": [1]}
{"op_code": 4, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "study_id": 0, "datetime_start": "2024-07-25T11:42:07.335452"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 0, "param_name": "lr", "param_value_internal": 6.896421114751126e-05, "distribution": "{\"name\": \"FloatDistribution\", \"attributes\": {\"step\": null, \"low\": 1e-05, \"high\": 0.1, \"log\": true}}"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 0, "param_name": "optimizer", "param_value_internal": 0, "distribution": "{\"name\": \"CategoricalDistribution\", \"attributes\": {\"choices\": [\"Adam\", \"SGD\", \"RMSprop\"]}}"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 0, "param_name": "filters", "param_value_internal": 0, "distribution": "{\"name\": \"CategoricalDistribution\", \"attributes\": {\"choices\": [32, 64]}}"}
{"op_code": 6, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 0, "state": 3, "values": null, "datetime_complete": "2024-07-25T11:42:07.372180"}
{"op_code": 4, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "study_id": 0, "datetime_start": "2024-07-25T11:42:38.184586"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 1, "param_name": "lr", "param_value_internal": 0.004413506973711808, "distribution": "{\"name\": \"FloatDistribution\", \"attributes\": {\"step\": null, \"low\": 1e-05, \"high\": 0.1, \"log\": true}}"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 1, "param_name": "optimizer", "param_value_internal": 2, "distribution": "{\"name\": \"CategoricalDistribution\", \"attributes\": {\"choices\": [\"Adam\", \"SGD\", \"RMSprop\"]}}"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 1, "param_name": "filters", "param_value_internal": 1, "distribution": "{\"name\": \"CategoricalDistribution\", \"attributes\": {\"choices\": [32, 64]}}"}
{"op_code": 6, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 1, "state": 3, "values": null, "datetime_complete": "2024-07-25T11:42:40.221492"}
{"op_code": 4, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "study_id": 0, "datetime_start": "2024-07-25T11:43:13.900783"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 2, "param_name": "lr", "param_value_internal": 0.009858907638988407, "distribution": "{\"name\": \"FloatDistribution\", \"attributes\": {\"step\": null, \"low\": 1e-05, \"high\": 0.1, \"log\": true}}"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 2, "param_name": "optimizer", "param_value_internal": 2, "distribution": "{\"name\": \"CategoricalDistribution\", \"attributes\": {\"choices\": [\"Adam\", \"SGD\", \"RMSprop\"]}}"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 2, "param_name": "filters", "param_value_internal": 0, "distribution": "{\"name\": \"CategoricalDistribution\", \"attributes\": {\"choices\": [32, 64]}}"}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 2, "step": 0, "intermediate_value": 0.012406982839193618}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 2, "step": 1, "intermediate_value": 0.012296284513483437}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 2, "step": 2, "intermediate_value": 0.012192022176946935}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 2, "step": 3, "intermediate_value": 0.01325888847546015}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 2, "step": 4, "intermediate_value": 0.01175757600621331}
{"op_code": 6, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 2, "state": 1, "values": [0.01175757600621331], "datetime_complete": "2024-07-25T12:59:25.440510"}
{"op_code": 4, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "study_id": 0, "datetime_start": "2024-07-25T12:59:25.447681"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 3, "param_name": "lr", "param_value_internal": 0.00375852733206065, "distribution": "{\"name\": \"FloatDistribution\", \"attributes\": {\"step\": null, \"low\": 1e-05, \"high\": 0.1, \"log\": true}}"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 3, "param_name": "optimizer", "param_value_internal": 0, "distribution": "{\"name\": \"CategoricalDistribution\", \"attributes\": {\"choices\": [\"Adam\", \"SGD\", \"RMSprop\"]}}"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 3, "param_name": "filters", "param_value_internal": 0, "distribution": "{\"name\": \"CategoricalDistribution\", \"attributes\": {\"choices\": [32, 64]}}"}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 3, "step": 0, "intermediate_value": 0.012742554306107707}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 3, "step": 1, "intermediate_value": 0.01393519094331604}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 3, "step": 2, "intermediate_value": 0.013373396859550501}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 3, "step": 3, "intermediate_value": 0.012453339947102671}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 3, "step": 4, "intermediate_value": 0.012303508424347635}
{"op_code": 6, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 3, "state": 1, "values": [0.012303508424347635], "datetime_complete": "2024-07-25T14:11:46.123018"}
{"op_code": 4, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "study_id": 0, "datetime_start": "2024-07-25T14:11:46.130124"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 4, "param_name": "lr", "param_value_internal": 0.08937778989479532, "distribution": "{\"name\": \"FloatDistribution\", \"attributes\": {\"step\": null, \"low\": 1e-05, \"high\": 0.1, \"log\": true}}"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 4, "param_name": "optimizer", "param_value_internal": 1, "distribution": "{\"name\": \"CategoricalDistribution\", \"attributes\": {\"choices\": [\"Adam\", \"SGD\", \"RMSprop\"]}}"}
{"op_code": 5, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 4, "param_name": "filters", "param_value_internal": 1, "distribution": "{\"name\": \"CategoricalDistribution\", \"attributes\": {\"choices\": [32, 64]}}"}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 4, "step": 0, "intermediate_value": 0.01562090049086887}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 4, "step": 1, "intermediate_value": 0.248305968297006}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 4, "step": 2, "intermediate_value": 0.21679665308311472}
{"op_code": 7, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 4, "step": 3, "intermediate_value": 0.05948987290931753}
{"op_code": 6, "worker_id": "0bc2c3c2-d18c-471c-8b1c-f925a91155e2-135722348189504", "trial_id": 4, "state": 3, "values": null, "datetime_complete": "2024-07-25T16:16:18.517776"}
19 changes: 19 additions & 0 deletions resources/configs/config_unet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"identifier": "UNet",
"network_config": {},

"train_config":{
"loss": "TripletLoss",
"tl_margin": 0.539,
"miner": true,
"miner_margin": 0.734,
"learning_rate": 5.945e-05,
"optimizer": "Adam",
"weight_decay": 0,
"batchsize": 64,
"patience": 50,
"aug_train_shift_distance": 2
},

"distance": "COSINE"
}
19 changes: 19 additions & 0 deletions resources/configs/config_unet_GN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"identifier": "UNet_GN",
"network_config": {},

"train_config":{
"loss": "TripletLoss",
"tl_margin": 0.539,
"miner": true,
"miner_margin": 0.734,
"learning_rate": 5.945e-05,
"optimizer": "Adam",
"weight_decay": 0,
"batchsize": 64,
"patience": 50,
"aug_train_shift_distance": 2
},

"distance": "COSINE"
}
4 changes: 2 additions & 2 deletions tomotwin/modules/common/io/mrc_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class MrcFormat:
def read(pth: str) -> np.array:
vol = None
try:
with mrcfile.open(pth, mode="r", permissive=True) as mrc:
vol = mrc.data
with mrcfile.open(pth, permissive=True) as mrc:
vol = mrc.data.astype(np.float32)
except ValueError as e:
raise Exception(f"Failed reading {pth}") from e
return vol
6 changes: 6 additions & 0 deletions tomotwin/modules/common/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ def label_filename(path: str) -> str:
def norm(vol: np.array) -> np.array:
"""Applies standard normalization"""
return (vol-np.mean(vol))/np.std(vol)

def norm2(vol: np.array) -> np.array:
min_val = np.min(vol)
max_val = np.max(vol)
normalized_vol = (vol - min_val) / (max_val - min_val)
return normalized_vol
2 changes: 1 addition & 1 deletion tomotwin/modules/training/mrctriplethandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MRCTripletHandler(TripletHandler):
@staticmethod
def read_mrc_and_norm(pth: str) -> np.array:
vol = MrcFormat.read(pth)
vol = preprocess.norm(vol)
vol = preprocess.norm2(vol)
return vol

def handle(self, triplet: FilePathTriplet) -> NumpyTriplet:
Expand Down
12 changes: 7 additions & 5 deletions tomotwin/modules/training/torchtrainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,16 @@ def run_batch(self, batch: Dict):
:param batch: Dictionary with batch data
:return: Loss of the batch
"""
anchor_vol = batch["anchor"].to(self.device, non_blocking=True)
positive_vol = batch["positive"].to(self.device, non_blocking=True)
negative_vol = batch["negative"].to(self.device, non_blocking=True)
full_input = torch.cat((anchor_vol,positive_vol,negative_vol), dim=0)
#anchor_vol = batch["anchor"].to(self.device, non_blocking=True)
#positive_vol = batch["positive"].to(self.device, non_blocking=True)
#negative_vol = batch["negative"].to(self.device, non_blocking=True)
anchor_vol = batch["anchor"]
positive_vol = batch["positive"]
negative_vol = batch["negative"]
full_input = torch.cat((anchor_vol,positive_vol,negative_vol), dim=0).to(self.device, non_blocking=True)
with autocast():
out = self.model.forward(full_input)
out = torch.split(out, anchor_vol.shape[0], dim=0)

loss = self.criterion(
out[0],
out[1],
Expand Down
Loading

0 comments on commit 3568e80

Please sign in to comment.