Skip to content

Commit afdb931

Browse files
author
rtb
committed
add desc
1 parent 8112ce1 commit afdb931

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Diff for: after_optimization.ipynb

+3-1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
"metadata": {},
179179
"outputs": [],
180180
"source": [
181+
"# Define model\n",
181182
"model = tf.keras.Sequential([\n",
182183
" tf.keras.layers.Conv2D(32, kernel_size=(3,3), input_shape=(1, 28, 28), activation='relu', data_format='channels_first'),\n",
183184
" tf.keras.layers.Conv2D(64, kernel_size=(3,3), activation='relu'),\n",
@@ -217,7 +218,7 @@
217218
"metadata": {},
218219
"outputs": [],
219220
"source": [
220-
"# Define train epochs\n",
221+
"# Define epochs\n",
221222
"epochs = 100\n",
222223
"\n",
223224
"# Compile model with XLA\n",
@@ -252,6 +253,7 @@
252253
"metadata": {},
253254
"outputs": [],
254255
"source": [
256+
"# Define model save path\n",
255257
"model_save_path = r'./latest.h5'\n",
256258
"\n",
257259
"# save model to file\n",

Diff for: after_optimization_multi.ipynb

+9-1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@
220220
"metadata": {},
221221
"outputs": [],
222222
"source": [
223+
"# Define and compile model in strategy scope\n",
223224
"with strategy.scope():\n",
224225
" model = tf.keras.Sequential([\n",
225226
" tf.keras.layers.Conv2D(32, kernel_size=(3,3), input_shape=(1, 28, 28), activation='relu', data_format='channels_first'),\n",
@@ -233,7 +234,8 @@
233234
" optimizer = tf.keras.optimizers.AdamW(learning_rate=0.001)\n",
234235
" loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)\n",
235236
" metrics = ['accuracy']\n",
236-
"\n",
237+
" \n",
238+
" # Compile model with XLA\n",
237239
" model.compile(optimizer=optimizer,\n",
238240
" loss=loss_fn,\n",
239241
" metrics=metrics,\n",
@@ -260,8 +262,13 @@
260262
"outputs": [],
261263
"source": [
262264
"epochs = 100\n",
265+
"\n",
266+
"# Compute interation per epoch for 'large but limited size dataset'\n",
267+
"# If dataset's size is infinite, set how many step to do on 1 epoch\n",
263268
"iteration_per_epoch = math.ceil(len(glob.glob(os.path.join(image_dir, '*/*.png')))/batch_size)\n",
264269
"\n",
270+
"\n",
271+
"# start training\n",
265272
"model.fit(dataloader, epochs=epochs, steps_per_epoch=iteration_per_epoch)\n"
266273
]
267274
},
@@ -284,6 +291,7 @@
284291
"metadata": {},
285292
"outputs": [],
286293
"source": [
294+
"# Define model save path\n",
287295
"model_save_path = r'./latest.h5'\n",
288296
"\n",
289297
"# save model to file\n",

Diff for: before_optimization.ipynb

+2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
"metadata": {},
182182
"outputs": [],
183183
"source": [
184+
"# Define model\n",
184185
"model = tf.keras.Sequential([\n",
185186
" tf.keras.layers.Conv2D(32, kernel_size=(3,3), input_shape=(1, 28, 28), activation='relu', data_format='channels_first'),\n",
186187
" tf.keras.layers.Conv2D(64, kernel_size=(3,3), activation='relu'),\n",
@@ -214,6 +215,7 @@
214215
"metadata": {},
215216
"outputs": [],
216217
"source": [
218+
"# Define epochs, batch size, dataset path\n",
217219
"epochs = 100\n",
218220
"batch_size = 2560\n",
219221
"images_path = './mnist_png/training'\n",

0 commit comments

Comments
 (0)