55
66from utils .data_loader import ImageClassificationDataLoader
77from utils .model import ImageClassifier
8+ from threading import Thread
89import tensorflow as tf
910import streamlit as st
1011import numpy as np
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+
3038BATCH_SIZES = [1 , 2 , 4 , 8 , 16 , 32 , 64 , 128 , 256 ]
3139
3240BACKBONES = [
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
171176if 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 ,
0 commit comments