GithubHelp home page GithubHelp logo

Comments (4)

amaralibey avatar amaralibey commented on September 24, 2024

Hello @wpumain,

Assuming that in_dim=400, it is likely that feature maps of size Cx20x20 are being used, which are then flattened to a size of Cx400. If mlp_ratio=1, the linear layer will have 400 outputs, which means it will have 400x400 parameters (excluding biases).
If the objective is to plot the learned parameters (not the activations), it is not necessary to feed an image and plot the outputs. Instead, we can plot the learned weights of the Linear layer.
For instance, the code snippet below shows the size of the parameters in the first Linear layer of the first Mixer block:

print(model.aggregator.mix[0].mix[1].weight.shape) # oututs torch.Size([400, 400])

To plot the weights of a single neuron, which is a line of 400 parameters from the weight matrix, it needs to be resized to 20x20 (remember that each neurone is connected to every feature map) and visualized.

all_neurones = model.aggregator.mix[0].mix[1].weight.reshape(-1, 20, 20).detach().cpu() # 400x20x20
random_idx = random.sample(list(range(400)), 1) # select a random idx from 0,399
random_neurone = all_neurones[random_idx] # 1x20x20
random_neurone = random_neurone.permute(1,2,0).numpy() #20x20x1
plt.imshow(random_neurone, cmap='RdBu', interpolation='bicubic')
plt.colorbar()
plt.axis('off')
plt.show()

from mixvpr.

wpumain avatar wpumain commented on September 24, 2024

Think you for your help .
Illustration of learned weights from a subset of 24 neurons from the first Feature-Mixer block. Blue color corresponds to positive weights and Red corresponds to negative weights.
What are positive weights?
what are negative weights?

from mixvpr.

amaralibey avatar amaralibey commented on September 24, 2024

Weights refer to the learned parameters of the neuron. If you use the code I shared above you'll get figure similar to the following: https://ibb.co/5MLV4h9

The color bar included in the visualization is self explanatory, blue corresponds to positive weights (parameters) of the neuron, while red corresponds to negative ones.

from mixvpr.

wpumain avatar wpumain commented on September 24, 2024

Think you for your help .

from mixvpr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.