use relax shapes to build less graphs
"import datetime\n",
"import warnings\n",
"\n",
+ "import tqdm\n",
+ "\n",
"import IPython\n",
"\n",
"import numpy as np\n",
"metadata": {},
"outputs": [],
"source": [
- "@tf.function\n",
- "def train_step(ground_truth_parameters, input_image):\n",
+ "@tf.function(experimental_relax_shapes=True)\n",
+ "def train_step(ground_truth_parameters, input_image, epoch):\n",
" with tf.GradientTape() as tape:\n",
" predicted_parameters = model(input_image, training=True)\n",
" loss = cost_function(predicted_parameters, ground_truth_parameters)\n",
" gradients = tape.gradient(loss, model.trainable_variables)\n",
" optimizer.apply_gradients(zip(gradients, model.trainable_variables))\n",
" \n",
- "# with summary_writer.as_default():\n",
- "# tf.summary.scalar('loss', loss, step=epoch)"
+ " reduced_loss = tf.reduce_mean(loss)\n",
+ "\n",
+ " with summary_writer.as_default():\n",
+ " tf.summary.scalar('loss', reduced_loss, step=epoch)"
]
},
{
" for epoch in range(epochs):\n",
" start = time.time()\n",
"\n",
- "# IPython.display.clear_output(wait=True)\n",
- "\n",
" for parameters, img in test_ds.take(1):\n",
" results_figures(model, img, parameters)\n",
"\n",
- " train_step(parameters, img)\n",
+ " iters_per_epoch = 10\n",
+ " for parameters, img in tqdm.tqdm(train_ds.take(iters_per_epoch), total=iters_per_epoch):\n",
+ " train_step(parameters, img, epoch)\n",
" \n",
- " # saving (checkpoint) the model every 20 epochs\n",
" if (epoch + 1) % 20 == 0:\n",
" checkpoint.save(file_prefix = checkpoint_prefix)\n",
"\n",
"metadata": {},
"outputs": [],
"source": [
- "# %load_ext tensorboard\n",
- "# %tensorboard --logdir {log_dir}"
+ "# tqdm.tqdm?"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "```bash\n",
+ "poetry run tensorboard --logdir examples/site-specific/cancer-care-associates/production/Winston\\ Lutz/prototyping/tf_model/logs/\n",
+ "```"
]
},
{
"outputs": [],
"source": [
"test_dataset = create_pipeline_dataset(1)\n",
- "train_dataset = create_pipeline_dataset(300)\n",
+ "train_dataset = create_pipeline_dataset(10)\n",
"fit(train_dataset, EPOCHS, test_dataset)"
]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
}
],
"metadata": {
