Skip to content

Commit

Permalink
📊Add support for TensorBoard in the example
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlechthaler committed Sep 13, 2021
1 parent 24de4a5 commit 7561e0b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,7 @@ _build/
dataset

# Model Artifacts (HDF5)
*.h5
*.h5

# TensorBoard
logs/
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ from covid_xray_classification.models.xception import Small
from covid_xray_classification.data import Downloader, Reshaper
from pandas import read_csv
from os.path import join
from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint, TensorBoard
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.preprocessing import image_dataset_from_directory
from tensorflow.keras.metrics import BinaryAccuracy,Precision,Recall
from keras.callbacks import ModelCheckpoint


# Download default dataset to default location
Expand Down Expand Up @@ -75,7 +74,10 @@ callbacks = [EarlyStopping("loss",
mode='min',
restore_best_weights=True),
# Save the model at the end of each epoch.
ModelCheckpoint("epoch_{epoch}.h5")]
ModelCheckpoint("epoch_{epoch}.h5"),
# Log data to directory logs for TensorBoard
TensorBoard(
log_dir="logs")]

# Specify the metrics we wish to evaluate at the end of each epoch.
metrics = ["accuracy",
Expand Down Expand Up @@ -127,6 +129,7 @@ model.fit(
callbacks=callbacks,
validation_data=val_ds)

# Save our model for later use.
model.save(join('dataset',
f"{model_name}.h5"))
```
8 changes: 5 additions & 3 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
from covid_xray_classification.data import Downloader, Reshaper
from pandas import read_csv
from os.path import join
from tensorflow.keras.callbacks import EarlyStopping
from tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint, TensorBoard
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.preprocessing import image_dataset_from_directory
from tensorflow.keras.metrics import BinaryAccuracy,Precision,Recall
from keras.callbacks import ModelCheckpoint


# Download default dataset to default location
Expand Down Expand Up @@ -59,7 +58,10 @@
mode='min',
restore_best_weights=True),
# Save the model at the end of each epoch.
ModelCheckpoint("epoch_{epoch}.h5")]
ModelCheckpoint("epoch_{epoch}.h5"),
# Log data to directory logs for TensorBoard
TensorBoard(
log_dir="logs")]

# Specify the metrics we wish to evaluate at the end of each epoch.
metrics = ["accuracy",
Expand Down

0 comments on commit 7561e0b

Please sign in to comment.