Created
December 23, 2020 14:48
-
-
Save hugozanini/745389f096aa6f691db8075e4d0e0e9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Publishing.ipynb", | |
"provenance": [] | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "K5gIl9aSVdGq" | |
}, | |
"source": [ | |
"#### Defining training parameters" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "YVps_k4JRGa7" | |
}, | |
"source": [ | |
"num_classes = 1\r\n", | |
"batch_size = 96\r\n", | |
"num_steps = 7500\r\n", | |
"num_eval_steps = 1000\r\n", | |
"\r\n", | |
"train_record_path = '/content/dataset/train.record'\r\n", | |
"test_record_path = '/content/dataset/test.record'\r\n", | |
"model_dir = '/content/training/'\r\n", | |
"labelmap_path = '/content/labelmap.pbtxt'\r\n", | |
"\r\n", | |
"pipeline_config_path = 'mobilenet_v2.config'\r\n", | |
"fine_tune_checkpoint = '/content/mobilenet_v2/mobilenet_v2.ckpt-1'" | |
], | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "BOiWE_mCVgap" | |
}, | |
"source": [ | |
"#### Editing config file" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "hH9pVN4qfbAb" | |
}, | |
"source": [ | |
"import re\r\n", | |
"\r\n", | |
"with open(pipeline_config_path) as f:\r\n", | |
" config = f.read()\r\n", | |
"\r\n", | |
"with open(pipeline_config_path, 'w') as f:\r\n", | |
"\r\n", | |
" # Set labelmap path\r\n", | |
" config = re.sub('label_map_path: \".*?\"', \r\n", | |
" 'label_map_path: \"{}\"'.format(labelmap_path), config)\r\n", | |
" \r\n", | |
" # Set fine_tune_checkpoint path\r\n", | |
" config = re.sub('fine_tune_checkpoint: \".*?\"',\r\n", | |
" 'fine_tune_checkpoint: \"{}\"'.format(fine_tune_checkpoint), config)\r\n", | |
" \r\n", | |
" # Set train tf-record file path\r\n", | |
" config = re.sub('(input_path: \".*?)(PATH_TO_BE_CONFIGURED/train)(.*?\")', \r\n", | |
" 'input_path: \"{}\"'.format(train_record_path), config)\r\n", | |
" \r\n", | |
" # Set test tf-record file path\r\n", | |
" config = re.sub('(input_path: \".*?)(PATH_TO_BE_CONFIGURED/val)(.*?\")', \r\n", | |
" 'input_path: \"{}\"'.format(test_record_path), config)\r\n", | |
" \r\n", | |
" # Set number of classes.\r\n", | |
" config = re.sub('num_classes: [0-9]+',\r\n", | |
" 'num_classes: {}'.format(num_classes), config)\r\n", | |
" \r\n", | |
" # Set batch size\r\n", | |
" config = re.sub('batch_size: [0-9]+',\r\n", | |
" 'batch_size: {}'.format(batch_size), config)\r\n", | |
" \r\n", | |
" # Set training steps\r\n", | |
" config = re.sub('num_steps: [0-9]+',\r\n", | |
" 'num_steps: {}'.format(num_steps), config)\r\n", | |
" \r\n", | |
" f.write(config)" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment