-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature space visualization tool + side by side gifs visual #29
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please:
- adjust the test
- add to the readme
- fix linting issues
- address comments
I know that's a lot - no rush! :)
kviz/visualizer.py
Outdated
@@ -416,6 +417,146 @@ def view_activations_for(self, X, filename='activations', duration=1000, x_color | |||
|
|||
self._stack_gifs(network_images, input_images, filename, duration) | |||
return | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the logic would involve matplotlib subplots and not combining gifs. Any reason not to do that?
kviz/visualizer.py
Outdated
plt.close() | ||
return np.asarray(im.open(filename + '.png')) | ||
|
||
def fit_in_feature_space(self, X, Y, snap_freq = 10, filename='feature_space', duration=1000, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like this to be an optional flag to the existing fit
api and not a whole new api.
83dcc71
to
f4d5798
Compare
@@ -19,7 +19,7 @@ | |||
'networkx', | |||
'pygraphviz', | |||
'matplotlib', | |||
'imageio' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add this back
@@ -3,6 +3,8 @@ | |||
from tensorflow.keras import layers | |||
import sklearn.datasets as datasets | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove these two lines
@@ -71,3 +73,18 @@ def test_regression(): | |||
|
|||
dg = Visualizer(model) | |||
dg.fit(X, Y, 100, 'test_regression', 100, epochs=10000, verbose=0, batch_size=200) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need an extra line here between functions
@@ -436,7 +509,6 @@ def view_activations_for(self, X, filename='activations', duration=1000, x_color | |||
self._stack_gifs(network_images, input_images, filename, duration) | |||
return | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add this line back
|
||
axes[1].imshow(self._snap_feature_space(X, Y, filename)) | ||
axes[1].axis('off') | ||
axes[1].set_title("Feature Space") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
axes[1].set_title("Feature Space") | |
axes[1].set_title("Feature Space At Hidden Layer 1") |
@@ -350,9 +396,36 @@ def fit(self, X, Y, snap_freq=10, filename='decision_boundary', duration=1000, * | |||
else: | |||
epochs = snap_freq | |||
|
|||
for _ in range(int(epochs / snap_freq)): | |||
temp_dir = "snapshots" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove this directory after the gifs are created
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also make this a hidden directory with a .
prefix
fig, axes = plt.subplots(1, 2, figsize=(12, 6)) | ||
|
||
axes[0].imshow(self._snap_decision_boundary(X, Y, filename)) | ||
axes[0].axis('off') | ||
axes[0].set_title("Input Space") | ||
|
||
axes[1].imshow(self._snap_feature_space(X, Y, filename)) | ||
axes[1].axis('off') | ||
axes[1].set_title("Feature Space") | ||
|
||
temp_filename = os.path.join(temp_dir, f"epoch_{epoch}.png") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ALl this should move inside snap_feature_space
Description of the change:
Added functions fit_in_feature_space and _snap_feature_space in visualizer.py to visualize the learned decision boundary in the feature space
Added function combine_gifs to visualize the learned decision boundary gifs side by side
Added test_feature_space in test_visualizer.py
Motivation for the change:
We wanted a way to visualize gifs side by side
Visualizing the decision boundary in the feature space can show how the network transforms data to make it linearly separable
Reviewer Checklist