Skip to content

Commit

Permalink
Feat: Revision will be updated with history after training
Browse files Browse the repository at this point in the history
  • Loading branch information
MortenTabaka committed Apr 8, 2023
1 parent a01d187 commit 44d8362
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 37 deletions.
107 changes: 71 additions & 36 deletions notebooks/model_training_template.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"start_time": "2023-04-02T11:28:52.549869Z",
"end_time": "2023-04-02T11:28:53.830123Z"
"start_time": "2023-04-08T23:47:38.038276Z",
"end_time": "2023-04-08T23:47:39.270313Z"
}
},
"outputs": [],
Expand Down Expand Up @@ -41,8 +41,8 @@
"id": "d8810a7e",
"metadata": {
"ExecuteTime": {
"start_time": "2023-04-02T11:28:53.829916Z",
"end_time": "2023-04-02T11:28:54.073122Z"
"start_time": "2023-04-08T23:47:39.311676Z",
"end_time": "2023-04-08T23:47:39.585346Z"
}
},
"outputs": [],
Expand All @@ -66,8 +66,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"start_time": "2023-04-02T11:28:54.074841Z",
"end_time": "2023-04-02T11:28:54.077617Z"
"start_time": "2023-04-08T23:47:39.587110Z",
"end_time": "2023-04-08T23:47:39.590034Z"
}
},
"outputs": [],
Expand All @@ -85,13 +85,13 @@
"id": "07420b7d",
"metadata": {
"ExecuteTime": {
"start_time": "2023-04-02T11:28:54.077193Z",
"end_time": "2023-04-02T11:28:54.118935Z"
"start_time": "2023-04-08T23:47:39.589220Z",
"end_time": "2023-04-08T23:47:39.622105Z"
}
},
"outputs": [],
"source": [
"VERSION = '10.0'\n",
"VERSION = '11.0'\n",
"\n",
"BATCH_SIZE = 4\n",
"IMG_HEIGHT = 512\n",
Expand All @@ -112,8 +112,8 @@
"execution_count": null,
"metadata": {
"ExecuteTime": {
"start_time": "2023-04-02T11:28:54.117758Z",
"end_time": "2023-04-02T11:28:54.121961Z"
"start_time": "2023-04-08T23:47:39.612064Z",
"end_time": "2023-04-08T23:47:39.622429Z"
}
},
"outputs": [],
Expand All @@ -127,8 +127,8 @@
"id": "465e97b5",
"metadata": {
"ExecuteTime": {
"start_time": "2023-04-02T11:28:54.165898Z",
"end_time": "2023-04-02T11:28:54.277219Z"
"start_time": "2023-04-08T23:50:31.940284Z",
"end_time": "2023-04-08T23:50:32.023117Z"
}
},
"outputs": [],
Expand Down Expand Up @@ -160,8 +160,8 @@
"metadata": {
"scrolled": false,
"ExecuteTime": {
"start_time": "2023-04-02T11:28:54.277374Z",
"end_time": "2023-04-02T11:28:54.385928Z"
"start_time": "2023-04-08T23:47:39.733598Z",
"end_time": "2023-04-08T23:47:39.891022Z"
}
},
"outputs": [],
Expand All @@ -184,8 +184,8 @@
"id": "93d76047",
"metadata": {
"ExecuteTime": {
"start_time": "2023-04-02T11:28:54.361974Z",
"end_time": "2023-04-02T11:28:54.446879Z"
"start_time": "2023-04-08T23:47:39.867743Z",
"end_time": "2023-04-08T23:47:39.918434Z"
}
},
"outputs": [],
Expand All @@ -207,8 +207,8 @@
"id": "04dab938",
"metadata": {
"ExecuteTime": {
"start_time": "2023-04-02T11:28:54.494120Z",
"end_time": "2023-04-02T11:28:54.494389Z"
"start_time": "2023-04-08T23:47:39.918645Z",
"end_time": "2023-04-08T23:47:39.920763Z"
}
},
"outputs": [],
Expand Down Expand Up @@ -244,8 +244,8 @@
"id": "c8a20742",
"metadata": {
"ExecuteTime": {
"start_time": "2023-04-02T11:28:54.494153Z",
"end_time": "2023-04-02T11:28:54.494459Z"
"start_time": "2023-04-08T23:47:39.920405Z",
"end_time": "2023-04-08T23:47:39.922574Z"
}
},
"outputs": [],
Expand Down Expand Up @@ -275,8 +275,8 @@
"id": "dbd9b7df",
"metadata": {
"ExecuteTime": {
"start_time": "2023-04-02T11:28:54.494181Z",
"end_time": "2023-04-02T11:28:54.494525Z"
"start_time": "2023-04-08T23:47:39.923006Z",
"end_time": "2023-04-08T23:47:39.963779Z"
}
},
"outputs": [],
Expand All @@ -295,7 +295,7 @@
"METRICS = [\"accuracy\", custom_mIoU_metric]\n",
"\n",
"# training the model\n",
"EPOCHS = 20\n"
"EPOCHS = 1\n"
]
},
{
Expand Down Expand Up @@ -328,8 +328,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"start_time": "2023-04-02T11:28:54.494256Z",
"end_time": "2023-04-02T11:28:54.494724Z"
"start_time": "2023-04-08T23:47:39.963689Z",
"end_time": "2023-04-08T23:47:39.964092Z"
}
}
},
Expand Down Expand Up @@ -367,8 +367,8 @@
"metadata": {
"collapsed": false,
"ExecuteTime": {
"start_time": "2023-04-02T11:28:54.494294Z",
"end_time": "2023-04-02T11:28:57.135769Z"
"start_time": "2023-04-08T23:47:39.963738Z",
"end_time": "2023-04-08T23:47:42.452636Z"
}
}
},
Expand All @@ -393,26 +393,34 @@
" os.makedirs(path)"
],
"metadata": {
"collapsed": false
"collapsed": false,
"ExecuteTime": {
"start_time": "2023-04-08T23:47:42.453466Z",
"end_time": "2023-04-08T23:47:42.455236Z"
}
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"path_best_dice_loss = PROJECT_PATH + f'/data/weights/{deeplab_model.revision}/best_loss/checkpoint'\n",
"dir_path_dice_loss= PROJECT_PATH + f'/data/weights/{deeplab_model.revision}/best_loss'\n",
"path_best_miou = PROJECT_PATH + f'/data/weights/{deeplab_model.revision}/best_miou/checkpoint'\n",
"dir_path_miou = PROJECT_PATH + f'/data/weights/{deeplab_model.revision}/best_miou'\n",
"path_best_dice_loss = PROJECT_PATH + f'/data/weights/{deeplab_model.model_architecture}_v{deeplab_model.revision}/best_loss/checkpoint'\n",
"dir_path_dice_loss= PROJECT_PATH + f'/data/weights/{deeplab_model.model_architecture}_v{deeplab_model.revision}/best_loss'\n",
"path_best_miou = PROJECT_PATH + f'/data/weights/{deeplab_model.model_architecture}_v{deeplab_model.revision}/best_miou/checkpoint'\n",
"dir_path_miou = PROJECT_PATH + f'/data/weights/{deeplab_model.model_architecture}_v{deeplab_model.revision}/best_miou'\n",
"\n",
"create_folders([\n",
" dir_path_dice_loss,\n",
" dir_path_miou,\n",
"])"
],
"metadata": {
"collapsed": false
"collapsed": false,
"ExecuteTime": {
"start_time": "2023-04-08T23:47:42.495633Z",
"end_time": "2023-04-08T23:47:42.495809Z"
}
}
},
{
Expand Down Expand Up @@ -451,7 +459,11 @@
"]"
],
"metadata": {
"collapsed": false
"collapsed": false,
"ExecuteTime": {
"start_time": "2023-04-08T23:47:42.495713Z",
"end_time": "2023-04-08T23:47:42.495979Z"
}
}
},
{
Expand All @@ -466,7 +478,12 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"ExecuteTime": {
"start_time": "2023-04-08T23:47:42.495754Z",
"end_time": "2023-04-08T23:47:51.306509Z"
}
},
"outputs": [],
"source": [
"history = model.fit(\n",
Expand All @@ -477,6 +494,24 @@
")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"deeplab_model.update_revision_with_training_history(history)"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"id": "75ccdccc",
Expand Down
8 changes: 8 additions & 0 deletions src/features/model_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,3 +176,11 @@ def decode_segmentation_mask_to_rgb(
rgb = stack([r, g, b], axis=2)
image = array_to_img(rgb)
return image


def dump_revision_yaml(to_dump):
yaml_filepath = get_absolute_path_to_project_location(
"models/models_revisions.yaml"
)
with open(yaml_filepath, "w") as f:
dump(to_dump, f, default_flow_style=False, sort_keys=False)
7 changes: 6 additions & 1 deletion src/models/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import tensorflow as tf

from src.features.model_features import revision_a_model
from src.features.model_features import dump_revision_yaml, revision_a_model, load_data_for_revision
from src.models.architectures import (
deeplabv3plus,
modified_v1_deeplabv3plus,
Expand Down Expand Up @@ -130,6 +130,11 @@ def save_model_revision(
metrics=self.metrics,
)

def update_revision_with_training_history(self, history: tf.keras.callbacks.History):
current_revision = load_data_for_revision(f"{self.model_architecture}_v{self.revision}")
current_revision["history"] = history.history
dump_revision_yaml(current_revision)

@property
def get_compile_parameters(self):
return [self.optimizer, self.loss_function, self.metrics]
Expand Down

0 comments on commit 44d8362

Please sign in to comment.