CS5720 - Week 9
Slide 170 of 180
Interactive Framework Demo
Framework Comparison
Model Builder
Performance Demo
🧠
TensorFlow
tensorflow_model.py
# TensorFlow/Keras approach
import
tensorflow
as
tf
# Build model
model = tf.keras.Sequential([ tf.keras.layers.
Dense
(
64
, activation=
'relu'
), tf.keras.layers.
Dense
(
32
, activation=
'relu'
), tf.keras.layers.
Dense
(
10
, activation=
'softmax'
) ])
# Compile and train
model.
compile
(optimizer=
'adam'
, loss=
'sparse_categorical_crossentropy'
) model.
fit
(X_train, y_train, epochs=
10
)
Run TensorFlow Code
🔥
PyTorch
pytorch_model.py
# PyTorch approach
import
torch
import
torch.nn
as
nn
# Define model class
class
Net
(nn.Module):
def
__init__
(self):
super
().__init__() self.fc1 = nn.
Linear
(
784
,
64
) self.fc2 = nn.
Linear
(
64
,
32
) self.fc3 = nn.
Linear
(
32
,
10
)
def
forward
(self, x): x = torch.
relu
(self.fc1(x)) x = torch.
relu
(self.fc2(x))
return
self.fc3(x) model =
Net
()
Run PyTorch Code
Interactive Model Builder
Hidden Layer 1 Size
128
Hidden Layer 2 Size
64
Dropout Rate
0.2
Learning Rate
0.001
Input
784
→
Hidden 1
128
→
Hidden 2
64
→
Output
10
Generate Code
Estimate Parameters
Framework Performance Comparison
🧠
TensorFlow
⭐⭐⭐⭐
Production Ready
🔥
PyTorch
⭐⭐⭐⭐⭐
Research Friendly
⚡
JAX
⭐⭐⭐⭐⭐
High Performance
Click any framework above to see detailed performance analysis!
← Previous
Next →
Prepared by Dr. Gorkem Kar
Modal Title
×
Modal content goes here...