Skip to content

Commit f40514b

Browse files
authored
Merge pull request #2 from animikhaich/dev
Verson 0.1.0 Release
2 parents 165f3a5 + 3259114 commit f40514b

File tree

7 files changed

+847
-181
lines changed

7 files changed

+847
-181
lines changed

CHANGELOG.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Version 0.1.0] - 2021-04-10
78

8-
## Version 0.1.0 Beta - 2021-04-06
9+
### Modified
10+
- Updated License from MIT to GNU AGPL V3
11+
- Re-shuffling:
12+
- `utils/data_loader.py` -> `core/data_loader.py`
13+
- `utils/model.py` -> `core/model.py`
14+
- Moved Custom Callbacks to new file: `utils/add_ons.py`
15+
16+
17+
## [Version 0.1.0 Beta] - 2021-04-06
918
### Added
1019
- Dockerfile
1120
- Launch Script (Dependency: [GNU Parallel](https://www.gnu.org/software/parallel/))
@@ -80,3 +89,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8089
- Adamax
8190
- Nadam
8291
- FTRL
92+
93+
94+
[Version 0.1.0 Beta]: https://github.com/animikhaich/Zero-Code-TF-Classifier/releases/tag/v0.1-beta
95+
[Version 0.1.0]: https://github.com/animikhaich/Zero-Code-TF-Classifier/releases/tag/v0.1

LICENSE

+661-21
Large diffs are not rendered by default.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Contributions are what make the open source community such an amazing place to b
176176

177177
## License
178178

179-
Distributed under the MIT License. See [LICENSE](LICENSE.md) for more information.
179+
Distributed under the [GNU AGPL V3 License](https://choosealicense.com/licenses/agpl-3.0/). See [LICENSE](LICENSE) for more information.
180180

181181

182182
## Contact
@@ -197,7 +197,7 @@ Distributed under the MIT License. See [LICENSE](LICENSE.md) for more informatio
197197
[stars-url]: https://github.com/animikhaich/Zero-Code-TF-Classifier/stargazers
198198
[issues-shield]: https://img.shields.io/github/issues/animikhaich/Zero-Code-TF-Classifier.svg?style=flat-square
199199
[issues-url]: https://github.com/animikhaich/Zero-Code-TF-Classifier/issues
200-
[license-shield]: https://img.shields.io/github/license/animikhaich/Semantic-Segmentation-using-AutoEncoders.svg?style=flat-square
200+
[license-shield]: https://img.shields.io/github/license/animikhaich/Zero-Code-TF-Classifier.svg?style=flat-square
201201
[license-url]: https://github.com/animikhaich/Zero-Code-TF-Classifier/blob/main/LICENSE
202202
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=flat-square&logo=linkedin&colorB=555
203203
[linkedin-url]: https://linkedin.com/in/animikh-aich/
File renamed without changes.

utils/model.py core/model.py

File renamed without changes.

main.py

+3-157
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
os.environ["TF_FORCE_GPU_ALLOW_GROWTH"] = "true"
1313
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "1"
1414

15-
from utils.data_loader import ImageClassificationDataLoader
16-
from utils.model import ImageClassifier
17-
from threading import Thread
15+
from core.data_loader import ImageClassificationDataLoader
16+
from core.model import ImageClassifier
17+
from utils.add_ons import CustomCallback
1818
import tensorflow as tf
1919
import streamlit as st
20-
import numpy as np
21-
import pandas as pd
22-
import plotly.graph_objs as go
2320

2421
# TODO: Add Support For Live Training Graphs (on_train_batch_end) without slowing down the Training Process
2522
# TODO: Add Supoort For EfficientNet - Fix Data Loader Input to be Un-Normalized Images
@@ -104,157 +101,6 @@
104101
st.title("Zero Code Tensorflow Classifier Trainer")
105102

106103

107-
class CustomCallback(tf.keras.callbacks.Callback):
108-
"""
109-
CustomCallback Keras Callback to Send Updates to Streamlit Dashboard
110-
111-
- Inherits from tf.keras.callbacks.Callback class
112-
- Sends Live Updates to the Dashboard
113-
- Allows Plotting Live Loss and Accuracy Curves
114-
- Allows Updating of Progress bar to track batch progress
115-
- Live plot only support Epoch Loss & Accuracy to improve training speed
116-
"""
117-
118-
def __init__(self, num_steps):
119-
"""
120-
__init__
121-
122-
Value Initializations
123-
124-
Args:
125-
num_steps (int): Total Number of Steps per Epoch
126-
"""
127-
self.num_steps = num_steps
128-
129-
# Constants (TODO: Need to Optimize)
130-
self.train_losses = []
131-
self.val_losses = []
132-
self.train_accuracies = []
133-
self.val_accuracies = []
134-
135-
# Progress
136-
self.epoch_text = st.empty()
137-
self.batch_progress = st.progress(0)
138-
self.status_text = st.empty()
139-
140-
# Charts
141-
self.loss_chart = st.empty()
142-
self.accuracy_chart = st.empty()
143-
144-
def update_graph(self, placeholder, items, title, xaxis, yaxis):
145-
"""
146-
update_graph Function to Update the plot.ly graphs on Streamlit
147-
148-
- Updates the Graphs Whenever called with the passed values
149-
- Only supports Line plots for now
150-
151-
Args:
152-
placeholder (st.empty()): streamlit placeholder object
153-
items (dict): Containing Name of the plot and values
154-
title (str): Title of the Plot
155-
xaxis (str): X-Axis Label
156-
yaxis (str): Y-Axis Label
157-
"""
158-
fig = go.Figure()
159-
for key in items.keys():
160-
fig.add_trace(
161-
go.Scatter(
162-
y=items[key],
163-
mode="lines+markers",
164-
name=key,
165-
)
166-
)
167-
fig.update_layout(title=title, xaxis_title=xaxis, yaxis_title=yaxis)
168-
placeholder.write(fig)
169-
170-
def on_train_batch_end(self, batch, logs=None):
171-
"""
172-
on_train_batch_end Update Progress Bar
173-
174-
At the end of each Training Batch, Update the progress bar
175-
176-
Args:
177-
batch (int): Current batch number
178-
logs (dict, optional): Training Metrics. Defaults to None.
179-
"""
180-
self.batch_progress.progress(batch / self.num_steps)
181-
182-
def on_epoch_begin(self, epoch, logs=None):
183-
"""
184-
on_epoch_begin
185-
186-
Update the Dashboard on the Current Epoch Number
187-
188-
Args:
189-
batch (int): Current batch number
190-
logs (dict, optional): Training Metrics. Defaults to None.
191-
"""
192-
self.epoch_text.text(f"Epoch: {epoch + 1}")
193-
194-
def on_train_begin(self, logs=None):
195-
"""
196-
on_train_begin
197-
198-
Status Update for the Dashboard with a message that training has started
199-
200-
Args:
201-
batch (int): Current batch number
202-
logs (dict, optional): Training Metrics. Defaults to None.
203-
"""
204-
self.status_text.info(
205-
"Training Started! Live Graphs will be shown on the completion of the First Epoch."
206-
)
207-
208-
def on_train_end(self, logs=None):
209-
"""
210-
on_train_end
211-
212-
Status Update for the Dashboard with a message that training has ended
213-
214-
Args:
215-
batch (int): Current batch number
216-
logs (dict, optional): Training Metrics. Defaults to None.
217-
"""
218-
self.status_text.success(
219-
f"Training Completed! Final Validation Accuracy: {logs['val_categorical_accuracy']*100:.2f}%"
220-
)
221-
st.balloons()
222-
223-
def on_epoch_end(self, epoch, logs=None):
224-
"""
225-
on_epoch_end
226-
227-
Update the Graphs with the train & val loss & accuracy curves (metrics)
228-
229-
Args:
230-
batch (int): Current batch number
231-
logs (dict, optional): Training Metrics. Defaults to None.
232-
"""
233-
self.train_losses.append(logs["loss"])
234-
self.val_losses.append(logs["val_loss"])
235-
self.train_accuracies.append(logs["categorical_accuracy"])
236-
self.val_accuracies.append(logs["val_categorical_accuracy"])
237-
238-
self.update_graph(
239-
self.loss_chart,
240-
{"Train Loss": self.train_losses, "Val Loss": self.val_losses},
241-
"Loss Curves",
242-
"Epochs",
243-
"Loss",
244-
)
245-
246-
self.update_graph(
247-
self.accuracy_chart,
248-
{
249-
"Train Accuracy": self.train_accuracies,
250-
"Val Accuracy": self.val_accuracies,
251-
},
252-
"Accuracy Curves",
253-
"Epochs",
254-
"Accuracy",
255-
)
256-
257-
258104
# Sidebar Configuration Parameters
259105
with st.sidebar:
260106
st.header("Training Configuration")

utils/add_ons.py

+167
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
__author__ = "Animikh Aich"
2+
__copyright__ = "Copyright 2021, Animikh Aich"
3+
__credits__ = ["Animikh Aich"]
4+
__license__ = "MIT"
5+
__version__ = "0.1.0"
6+
__maintainer__ = "Animikh Aich"
7+
__email__ = "[email protected]"
8+
__status__ = "staging"
9+
10+
import os
11+
12+
os.environ["TF_FORCE_GPU_ALLOW_GROWTH"] = "true"
13+
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "1"
14+
import tensorflow as tf
15+
import streamlit as st
16+
import plotly.graph_objs as go
17+
18+
19+
class CustomCallback(tf.keras.callbacks.Callback):
20+
"""
21+
CustomCallback Keras Callback to Send Updates to Streamlit Dashboard
22+
23+
- Inherits from tf.keras.callbacks.Callback class
24+
- Sends Live Updates to the Dashboard
25+
- Allows Plotting Live Loss and Accuracy Curves
26+
- Allows Updating of Progress bar to track batch progress
27+
- Live plot only support Epoch Loss & Accuracy to improve training speed
28+
"""
29+
30+
def __init__(self, num_steps):
31+
"""
32+
__init__
33+
34+
Value Initializations
35+
36+
Args:
37+
num_steps (int): Total Number of Steps per Epoch
38+
"""
39+
self.num_steps = num_steps
40+
41+
# Constants (TODO: Need to Optimize)
42+
self.train_losses = []
43+
self.val_losses = []
44+
self.train_accuracies = []
45+
self.val_accuracies = []
46+
47+
# Progress
48+
self.epoch_text = st.empty()
49+
self.batch_progress = st.progress(0)
50+
self.status_text = st.empty()
51+
52+
# Charts
53+
self.loss_chart = st.empty()
54+
self.accuracy_chart = st.empty()
55+
56+
def update_graph(self, placeholder, items, title, xaxis, yaxis):
57+
"""
58+
update_graph Function to Update the plot.ly graphs on Streamlit
59+
60+
- Updates the Graphs Whenever called with the passed values
61+
- Only supports Line plots for now
62+
63+
Args:
64+
placeholder (st.empty()): streamlit placeholder object
65+
items (dict): Containing Name of the plot and values
66+
title (str): Title of the Plot
67+
xaxis (str): X-Axis Label
68+
yaxis (str): Y-Axis Label
69+
"""
70+
fig = go.Figure()
71+
for key in items.keys():
72+
fig.add_trace(
73+
go.Scatter(
74+
y=items[key],
75+
mode="lines+markers",
76+
name=key,
77+
)
78+
)
79+
fig.update_layout(title=title, xaxis_title=xaxis, yaxis_title=yaxis)
80+
placeholder.write(fig)
81+
82+
def on_train_batch_end(self, batch, logs=None):
83+
"""
84+
on_train_batch_end Update Progress Bar
85+
86+
At the end of each Training Batch, Update the progress bar
87+
88+
Args:
89+
batch (int): Current batch number
90+
logs (dict, optional): Training Metrics. Defaults to None.
91+
"""
92+
self.batch_progress.progress(batch / self.num_steps)
93+
94+
def on_epoch_begin(self, epoch, logs=None):
95+
"""
96+
on_epoch_begin
97+
98+
Update the Dashboard on the Current Epoch Number
99+
100+
Args:
101+
batch (int): Current batch number
102+
logs (dict, optional): Training Metrics. Defaults to None.
103+
"""
104+
self.epoch_text.text(f"Epoch: {epoch + 1}")
105+
106+
def on_train_begin(self, logs=None):
107+
"""
108+
on_train_begin
109+
110+
Status Update for the Dashboard with a message that training has started
111+
112+
Args:
113+
batch (int): Current batch number
114+
logs (dict, optional): Training Metrics. Defaults to None.
115+
"""
116+
self.status_text.info(
117+
"Training Started! Live Graphs will be shown on the completion of Each Epoch."
118+
)
119+
120+
def on_train_end(self, logs=None):
121+
"""
122+
on_train_end
123+
124+
Status Update for the Dashboard with a message that training has ended
125+
126+
Args:
127+
batch (int): Current batch number
128+
logs (dict, optional): Training Metrics. Defaults to None.
129+
"""
130+
self.status_text.success(
131+
f"Training Completed! Final Validation Accuracy: {logs['val_categorical_accuracy']*100:.2f}%"
132+
)
133+
st.balloons()
134+
135+
def on_epoch_end(self, epoch, logs=None):
136+
"""
137+
on_epoch_end
138+
139+
Update the Graphs with the train & val loss & accuracy curves (metrics)
140+
141+
Args:
142+
batch (int): Current batch number
143+
logs (dict, optional): Training Metrics. Defaults to None.
144+
"""
145+
self.train_losses.append(logs["loss"])
146+
self.val_losses.append(logs["val_loss"])
147+
self.train_accuracies.append(logs["categorical_accuracy"])
148+
self.val_accuracies.append(logs["val_categorical_accuracy"])
149+
150+
self.update_graph(
151+
self.loss_chart,
152+
{"Train Loss": self.train_losses, "Val Loss": self.val_losses},
153+
"Loss Curves",
154+
"Epochs",
155+
"Loss",
156+
)
157+
158+
self.update_graph(
159+
self.accuracy_chart,
160+
{
161+
"Train Accuracy": self.train_accuracies,
162+
"Val Accuracy": self.val_accuracies,
163+
},
164+
"Accuracy Curves",
165+
"Epochs",
166+
"Accuracy",
167+
)

0 commit comments

Comments
 (0)