Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

SunehB
Copy link

@SunehB SunehB commented Nov 16, 2024

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

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient test coverage
  • Docs updated
  • Commit messages sensible and descriptive

Copy link
Owner

@gallettilance gallettilance left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please:

  1. adjust the test
  2. add to the readme
  3. fix linting issues
  4. address comments

I know that's a lot - no rush! :)

@@ -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

Copy link
Owner

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?

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):
Copy link
Owner

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.

@@ -19,7 +19,7 @@
'networkx',
'pygraphviz',
'matplotlib',
'imageio'
Copy link
Owner

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


Copy link
Owner

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)

Copy link
Owner

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


Copy link
Owner

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")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"
Copy link
Owner

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

Copy link
Owner

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

Comment on lines +411 to +421
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")
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants