Skip to content

Commit 36affe4

Browse files
committed
Updated Models List, Added Tensorboard, Added Launch Script
1 parent a666a3e commit 36affe4

File tree

4 files changed

+36
-30
lines changed

4 files changed

+36
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ dmypy.json
140140
.history/
141141

142142
# Specific Files/Folders
143+
model/
143144
logs*
144145
old_data/
145146
test*

launch.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
parallel ::: "streamlit run main.py" "tensorboard --logdir logs/tensorboard --host 0.0.0.0 --port 6006"

main.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from utils.data_loader import ImageClassificationDataLoader
77
from utils.model import ImageClassifier
8+
from threading import Thread
89
import tensorflow as tf
910
import streamlit as st
1011
import numpy as np
@@ -27,27 +28,34 @@
2728
"FTRL": tf.keras.optimizers.Ftrl(),
2829
}
2930

31+
TRAINING_PRECISION = {
32+
"Full Precision (FP32)": "float32",
33+
"Mixed Precision (GPU - FP16) ": "mixed_float16",
34+
"Mixed Precision (TPU - BF16) ": "mixed_bfloat16",
35+
}
36+
37+
3038
BATCH_SIZES = [1, 2, 4, 8, 16, 32, 64, 128, 256]
3139

3240
BACKBONES = [
33-
"MobileNet",
3441
"MobileNetV2",
42+
"ResNet50V2",
43+
"Xception",
44+
"InceptionV3",
45+
"VGG16",
46+
"VGG19",
3547
"ResNet50",
3648
"ResNet101",
3749
"ResNet152",
38-
"ResNet50V2",
3950
"ResNet101V2",
4051
"ResNet152V2",
41-
"VGG16",
42-
"VGG19",
43-
"Xception",
44-
"InceptionV3",
4552
"InceptionResNetV2",
4653
"DenseNet121",
4754
"DenseNet169",
4855
"DenseNet201",
4956
"NASNetMobile",
5057
"NASNetLarge",
58+
"MobileNet",
5159
]
5260

5361

@@ -135,19 +143,11 @@ def on_epoch_end(self, epoch, logs=None):
135143
# Enter Path for Train and Val Dataset
136144
train_data_dir = st.text_input(
137145
"Train Data Directory (Absolute Path)",
138-
"/home/ani/Documents/pycodes/Dataset/gender/Sample/",
146+
"/home/ani/Documents/pycodes/Dataset/gender/Training/",
139147
)
140148
val_data_dir = st.text_input(
141149
"Validation Data Directory (Absolute Path)",
142-
"/home/ani/Documents/pycodes/Dataset/gender/Sample/",
143-
)
144-
145-
# Enter Path for Model Weights and Training Logs (Tensorboard)
146-
keras_weights_path = st.text_input(
147-
"Keras Weights File Path (Absolute Path)", "logs/models/weights.h5"
148-
)
149-
tensorboard_logs_path = st.text_input(
150-
"Tensorboard Logs Directory (Absolute Path)", "logs/tensorboard"
150+
"/home/ani/Documents/pycodes/Dataset/gender/Validation/",
151151
)
152152

153153
# Select Backbone
@@ -162,23 +162,30 @@ def on_epoch_end(self, epoch, logs=None):
162162
# Select Number of Epochs
163163
selected_epochs = st.number_input("Max Number of Epochs", 1, 500, 100)
164164

165-
# Select Number of Epochs
166-
selected_input_shape = st.number_input("Input Image Shape", 64, 2000, 224)
165+
# Select Input Image Shape
166+
selected_input_shape = st.number_input("Input Image Shape", 64, 600, 224)
167+
168+
# Mixed Precision Training
169+
selected_precision = st.selectbox(
170+
"Training Precision", list(TRAINING_PRECISION.keys())
171+
)
167172

168173
# Start Training Button
169174
start_training = st.button("Start Training")
170175

171176
if start_training:
177+
input_shape = (selected_input_shape, selected_input_shape, 3)
178+
172179
train_data_loader = ImageClassificationDataLoader(
173180
data_dir=train_data_dir,
174-
image_dims=(224, 224),
181+
image_dims=input_shape[:2],
175182
grayscale=False,
176183
num_min_samples=100,
177184
)
178185

179186
val_data_loader = ImageClassificationDataLoader(
180187
data_dir=val_data_dir,
181-
image_dims=(224, 224),
188+
image_dims=input_shape[:2],
182189
grayscale=False,
183190
num_min_samples=100,
184191
)
@@ -192,18 +199,15 @@ def on_epoch_end(self, epoch, logs=None):
192199

193200
classifier = ImageClassifier(
194201
backbone=selected_backbone,
195-
input_shape=(224, 224, 3),
202+
input_shape=input_shape,
196203
classes=train_data_loader.get_num_classes(),
204+
optimizer=selected_optimizer,
197205
)
198206

199-
classifier.set_keras_weights_path(keras_weights_path)
200-
classifier.set_tensorboard_path(tensorboard_logs_path)
201-
202207
classifier.init_callbacks(
203208
[CustomCallback(train_data_loader.get_num_steps())],
204209
)
205-
206-
classifier.set_optimizer(selected_optimizer)
210+
classifier.set_precision(TRAINING_PRECISION[selected_precision])
207211

208212
classifier.train(
209213
train_generator,

utils/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ def __init__(
4646

4747
# Default Initializations
4848
self.timestamp = datetime.now().strftime("%d-%m-%Y_%H-%M-%S")
49-
self.keras_weights_path = f"/model/weights/keras/{backbone}_{self.timestamp}.h5"
49+
self.keras_weights_path = f"model/weights/keras/{backbone}_{self.timestamp}.h5"
5050
self.saved_model_weights_path = (
51-
f"/model/weights/savedmodel/{backbone}_{self.timestamp}/"
51+
f"model/weights/savedmodel/{backbone}_{self.timestamp}"
5252
)
53-
self.tensorboard_logs_path = f"/model/logs/{backbone}_{self.timestamp}/"
53+
self.tensorboard_logs_path = f"logs/tensorboard/{backbone}_{self.timestamp}"
5454

5555
def __create_directory(self, path):
5656
if not os.path.isdir(path):
@@ -171,7 +171,7 @@ def set_num_classes(self, num_classes):
171171
def get_num_classes(self):
172172
return self.classes
173173

174-
def set_input_sape(self, input_shape):
174+
def set_input_shape(self, input_shape):
175175
self.input_shape = input_shape
176176

177177
def get_input_shape(self):

0 commit comments

Comments
 (0)