Skip to content

Commit

Permalink
Merge pull request #11152 from tensorflow:sineeli-patch-16
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 603518825
  • Loading branch information
tensorflower-gardener committed Feb 2, 2024
2 parents 467fbf7 + 63b0307 commit 599e34c
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions docs/vision/semantic_segmentation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
"source": [
"# Semantic Segmentation with Model Garden\n",
"\n",
"\u003ctable class=\"tfo-notebook-buttons\" align=\"left\"\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://www.tensorflow.org/tfmodels/vision/semantic_segmentation\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" /\u003eView on TensorFlow.org\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/models/blob/master/docs/vision/semantic_segmentation.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" /\u003eRun in Google Colab\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca target=\"_blank\" href=\"https://github.com/tensorflow/models/blob/master/docs/vision/semantic_segmentation.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" /\u003eView on GitHub\u003c/a\u003e\n",
" \u003c/td\u003e\n",
" \u003ctd\u003e\n",
" \u003ca href=\"https://storage.googleapis.com/tensorflow_docs/models/docs/vision/semantic_segmentation.ipynb\"\u003e\u003cimg src=\"https://www.tensorflow.org/images/download_logo_32px.png\" /\u003eDownload notebook\u003c/a\u003e\n",
" \u003c/td\u003e\n",
"\u003c/table\u003e"
"<table class=\"tfo-notebook-buttons\" align=\"left\">\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://www.tensorflow.org/tfmodels/vision/semantic_segmentation\"><img src=\"https://www.tensorflow.org/images/tf_logo_32px.png\" />View on TensorFlow.org</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/tensorflow/models/blob/master/docs/vision/semantic_segmentation.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n",
" </td>\n",
" <td>\n",
" <a target=\"_blank\" href=\"https://github.com/tensorflow/models/blob/master/docs/vision/semantic_segmentation.ipynb\"><img src=\"https://www.tensorflow.org/images/GitHub-Mark-32px.png\" />View on GitHub</a>\n",
" </td>\n",
" <td>\n",
" <a href=\"https://storage.googleapis.com/tensorflow_docs/models/docs/vision/semantic_segmentation.ipynb\"><img src=\"https://www.tensorflow.org/images/download_logo_32px.png\" />Download notebook</a>\n",
" </td>\n",
"</table>"
]
},
{
Expand Down Expand Up @@ -95,7 +95,7 @@
},
"outputs": [],
"source": [
"!pip install -U -q \"tensorflow\u003e=2.9.2\" \"tf-models-official\""
"!pip install -U -q \"tf-models-official\""
]
},
{
Expand Down Expand Up @@ -138,6 +138,7 @@
"import orbit\n",
"import tensorflow_models as tfm\n",
"from official.vision.data import tfrecord_lib\n",
"from official.vision.utils import summary_manager\n",
"from official.vision.serving import export_saved_model_lib\n",
"from official.vision.utils.object_detection import visualization_utils\n",
"\n",
Expand Down Expand Up @@ -428,7 +429,8 @@
"exp_config.task.validation_data.output_size = [HEIGHT, WIDTH]\n",
"exp_config.task.validation_data.preserve_aspect_ratio = False\n",
"exp_config.task.validation_data.groundtruth_padded_size = [HEIGHT, WIDTH]\n",
"exp_config.task.validation_data.seed = 21 # Reproducable Validation Data"
"exp_config.task.validation_data.seed = 21 # Reproducable Validation Data\n",
"exp_config.task.validation_data.resize_eval_groundtruth = True # To enable validation loss"
]
},
{
Expand Down Expand Up @@ -540,7 +542,7 @@
"source": [
"## Create the `Task` object (`tfm.core.base_task.Task`) from the `config_definitions.TaskConfig`.\n",
"\n",
"The `Task` object has all the methods necessary for building the dataset, building the model, and running training \u0026 evaluation. These methods are driven by `tfm.core.train_lib.run_experiment`."
"The `Task` object has all the methods necessary for building the dataset, building the model, and running training & evaluation. These methods are driven by `tfm.core.train_lib.run_experiment`."
]
},
{
Expand Down Expand Up @@ -597,7 +599,7 @@
},
"outputs": [],
"source": [
"def display(display_list):\n",
"def plot_masks(display_list):\n",
" plt.figure(figsize=(15, 15))\n",
"\n",
" title = ['Input Image', 'True Mask', 'Predicted Mask']\n",
Expand Down Expand Up @@ -636,7 +638,7 @@
"num_examples = 3\n",
"\n",
"for images, masks in task.build_inputs(exp_config.task.train_data).take(num_examples):\n",
" display([images[0], masks['masks'][0]])"
" plot_masks([images[0], masks['masks'][0]])"
]
},
{
Expand All @@ -657,12 +659,15 @@
},
"outputs": [],
"source": [
"\n",
"model, eval_logs = tfm.core.train_lib.run_experiment(\n",
" distribution_strategy=distribution_strategy,\n",
" task=task,\n",
" mode='train_and_eval',\n",
" params=exp_config,\n",
" model_dir=model_dir,\n",
" eval_summary_manager=summary_manager.maybe_build_eval_summary_manager(\n",
" params=exp_config, model_dir=model_dir),\n",
" run_post_eval=True)"
]
},
Expand Down Expand Up @@ -764,7 +769,7 @@
" image = tf.cast(image, dtype=tf.uint8)\n",
" mask = tf.image.resize(record['segmentation_mask'], size=[HEIGHT, WIDTH])\n",
" predicted_mask = model_fn(tf.expand_dims(record['image'], axis=0))\n",
" display([image, mask, create_mask(predicted_mask['logits'])])"
" plot_masks([image, mask, create_mask(predicted_mask['logits'])])"
]
}
],
Expand Down

0 comments on commit 599e34c

Please sign in to comment.