Skip to content

Commit

Permalink
Migrate 3D_image_classification tutorial to Keras(all backends) (#1723)
Browse files Browse the repository at this point in the history
* Convert 3D_image_classification to Keras3(all backend)

* Updated last_modified date

* Generated .md and .ipyng files

* added generated files
  • Loading branch information
SuryanarayanaY authored Jan 21, 2024
1 parent a52a1c5 commit f10c0c4
Show file tree
Hide file tree
Showing 6 changed files with 1,236 additions and 113 deletions.
18 changes: 9 additions & 9 deletions examples/vision/3D_image_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Title: 3D image classification from CT scans
Author: [Hasib Zunair](https://twitter.com/hasibzunair)
Date created: 2020/09/23
Last modified: 2020/09/23
Last modified: 2024/01/11
Description: Train a 3D convolutional neural network to predict presence of pneumonia.
Accelerator: GPU
"""
Expand All @@ -17,9 +17,9 @@
## References
- [A survey on Deep Learning Advances on Different 3D DataRepresentations](https://arxiv.org/pdf/1808.01462.pdf)
- [A survey on Deep Learning Advances on Different 3D DataRepresentations](https://arxiv.org/abs/1808.01462)
- [VoxNet: A 3D Convolutional Neural Network for Real-Time Object Recognition](https://www.ri.cmu.edu/pub_files/2015/9/voxnet_maturana_scherer_iros15.pdf)
- [FusionNet: 3D Object Classification Using MultipleData Representations](http://3ddl.cs.princeton.edu/2016/papers/Hegde_Zadeh.pdf)
- [FusionNet: 3D Object Classification Using MultipleData Representations](https://arxiv.org/abs/1607.05695)
- [Uniformizing Techniques to Process CT scans with 3D CNNs for Tuberculosis Prediction](https://arxiv.org/abs/2007.13224)
"""
"""
Expand All @@ -29,10 +29,10 @@
import os
import zipfile
import numpy as np
import tensorflow as tf
import tensorflow as tf # for data preprocessing

from tensorflow import keras
from tensorflow.keras import layers
import keras
from keras import layers

"""
## Downloading the MosMedData: Chest CT Scans with COVID-19 Related Findings
Expand Down Expand Up @@ -211,7 +211,6 @@ def process_scan(path):
from scipy import ndimage


@tf.function
def rotate(volume):
"""Rotate the volume by a few degrees"""

Expand Down Expand Up @@ -375,11 +374,12 @@ def get_model(width=128, height=128, depth=64):
loss="binary_crossentropy",
optimizer=keras.optimizers.Adam(learning_rate=lr_schedule),
metrics=["acc"],
run_eagerly=True,
)

# Define callbacks.
checkpoint_cb = keras.callbacks.ModelCheckpoint(
"3d_image_classification.h5", save_best_only=True
"3d_image_classification.keras", save_best_only=True
)
early_stopping_cb = keras.callbacks.EarlyStopping(monitor="val_acc", patience=15)

Expand Down Expand Up @@ -426,7 +426,7 @@ def get_model(width=128, height=128, depth=64):
"""

# Load best weights.
model.load_weights("3d_image_classification.h5")
model.load_weights("3d_image_classification.keras")
prediction = model.predict(np.expand_dims(x_val[0], axis=0))[0]
scores = [1 - prediction[0], prediction[0]]

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions examples/vision/ipynb/3D_image_classification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"\n",
"**Author:** [Hasib Zunair](https://twitter.com/hasibzunair)<br>\n",
"**Date created:** 2020/09/23<br>\n",
"**Last modified:** 2020/09/23<br>\n",
"**Last modified:** 2024/01/11<br>\n",
"**Description:** Train a 3D convolutional neural network to predict presence of pneumonia."
]
},
Expand All @@ -30,9 +30,9 @@
"\n",
"## References\n",
"\n",
"- [A survey on Deep Learning Advances on Different 3D DataRepresentations](https://arxiv.org/pdf/1808.01462.pdf)\n",
"- [A survey on Deep Learning Advances on Different 3D DataRepresentations](https://arxiv.org/abs/1808.01462)\n",
"- [VoxNet: A 3D Convolutional Neural Network for Real-Time Object Recognition](https://www.ri.cmu.edu/pub_files/2015/9/voxnet_maturana_scherer_iros15.pdf)\n",
"- [FusionNet: 3D Object Classification Using MultipleData Representations](http://3ddl.cs.princeton.edu/2016/papers/Hegde_Zadeh.pdf)\n",
"- [FusionNet: 3D Object Classification Using MultipleData Representations](https://arxiv.org/abs/1607.05695)\n",
"- [Uniformizing Techniques to Process CT scans with 3D CNNs for Tuberculosis Prediction](https://arxiv.org/abs/2007.13224)"
]
},
Expand All @@ -56,10 +56,10 @@
"import os\n",
"import zipfile\n",
"import numpy as np\n",
"import tensorflow as tf\n",
"import tensorflow as tf # for data preprocessing\n",
"\n",
"from tensorflow import keras\n",
"from tensorflow.keras import layers"
"import keras\n",
"from keras import layers"
]
},
{
Expand Down Expand Up @@ -308,7 +308,6 @@
"from scipy import ndimage\n",
"\n",
"\n",
"@tf.function\n",
"def rotate(volume):\n",
" \"\"\"Rotate the volume by a few degrees\"\"\"\n",
"\n",
Expand Down Expand Up @@ -542,11 +541,12 @@
" loss=\"binary_crossentropy\",\n",
" optimizer=keras.optimizers.Adam(learning_rate=lr_schedule),\n",
" metrics=[\"acc\"],\n",
" run_eagerly=True,\n",
")\n",
"\n",
"# Define callbacks.\n",
"checkpoint_cb = keras.callbacks.ModelCheckpoint(\n",
" \"3d_image_classification.h5\", save_best_only=True\n",
" \"3d_image_classification.keras\", save_best_only=True\n",
")\n",
"early_stopping_cb = keras.callbacks.EarlyStopping(monitor=\"val_acc\", patience=15)\n",
"\n",
Expand Down Expand Up @@ -626,7 +626,7 @@
"outputs": [],
"source": [
"# Load best weights.\n",
"model.load_weights(\"3d_image_classification.h5\")\n",
"model.load_weights(\"3d_image_classification.keras\")\n",
"prediction = model.predict(np.expand_dims(x_val[0], axis=0))[0]\n",
"scores = [1 - prediction[0], prediction[0]]\n",
"\n",
Expand Down
Loading

0 comments on commit f10c0c4

Please sign in to comment.