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

[draft] Add Weight Visualization #1492

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

staddy
Copy link
Contributor

@staddy staddy commented Feb 7, 2023

This pull request adds a weight visualization implementation example:
image
On expanding a compatible node's tensor (with dim >= 2) a weight visualization GUI appears in property side-bar.
To visualize a tensor as a 2d image you need to:

  1. Select axes of the tensor that will be used as x and y of the image (use the checkboxes of "axes selector", exactly two axes should be selected, the first selected axis is (x) and the second is (y)).
  2. Select the values of the other axes that will be fixed with "values selector" - all not selected axes should have a fixed value.
  3. The weights will appear as a 2d heatmap below. Blue color is the minimum value, red color is the maximum value.
    For example: you are visualizing a tensor of shape (32, 3, 3, 3).
    Let's assume you have selected the 2 lower checkboxes and fixed first axis value as 10 and the second axis value as 1.
    So the top left pixel of the image corresponds to tensor[10][1][0][0] value.
    The bottom right pixel - tensor[10][1][2][2] value.

Stanislav Ponkrashov added 4 commits February 3, 2023 13:53
This commit adds weight visualization example.

ONE-vscode-DCO-1.0-Signed-off-by: Stanislav Ponkrashov
<s.ponkrashov@samsung.com>
@staddy staddy marked this pull request as draft February 7, 2023 10:55
@seanshpark
Copy link
Contributor

seanshpark commented Feb 7, 2023

@staddy , is this your current change? why I'm asking

  • I expect property window show new properties (I didn't pull and checked)
  • when clicked, there will be no feedback in the UI; I don't expect this to be a full working draft I don't see related codes as of now in the change

CircleGraph is shared code, as of now, used in circle graph view, partition editor and visquv

  • I don't expect this property be visible in partition editor nor in visquv

What is your user scenario ?

  • please describe in detail
  • from opening the folder and ....

@staddy
Copy link
Contributor Author

staddy commented Feb 8, 2023

@seanshpark, yes, this is what is implemented in the draft.
Property window shows additional property: VisualTensorView.
The implemented UI works as described, the draft is kind of full working if we are talking about visualizing any 2d subarray of a tensor.
Currently the property appears for any suitable tensor, so if the code is shared, I need to implement disabling the feature.
Current scenario:

  • open a folder with a *.circle file
  • click on the *.circle file
  • click on a node that contains 2+d tensors
  • expand the 2+d tensor properties in property window
  • the implemented UI appears and functions

@staddy
Copy link
Contributor Author

staddy commented Feb 8, 2023

  • I don't see related codes as of now in the change

Currently the code just changes the default behavior of sidebar, adding a new property to any tensor with >= 2 axes.
I thought this implementation is more natural.
Now I can add a setting to disable the visualizer by default.
Should it be a global setting? Or, maybe, a control that allow to switch between text and visual representation?
Or just always enable the visualizer when initializing the sidebar in graph view?

@seanshpark
Copy link
Contributor

seanshpark commented Feb 8, 2023

Should it be a global setting? Or, ...

@staddy , have you read my comment #1492 (comment) ? or you don't understand it? please ask if you can't catch the meaning

CircleGraph is shared code, as of now, used in circle graph view, partition editor and visquv

  • I don't expect this property be visible in partition editor nor in visquv

@seanshpark
Copy link
Contributor

I would like to see this draft provide your full Current scenario:

@staddy
Copy link
Contributor Author

staddy commented Feb 8, 2023

Now VisualTensorView property is enabled only in circle graph and disabled in partition editor and visquv.
The draft provides full "Current scenario".

@staddy
Copy link
Contributor Author

staddy commented Feb 8, 2023

Current state:
image
Added UI to modify scale and swap axes.

@seanshpark
Copy link
Contributor

@staddy , I've got your change but I can't see the weight bars. Please describe the condition of the model that shows the bar.

@staddy
Copy link
Contributor Author

staddy commented Feb 8, 2023

@seanshpark, 'weights' a property of some nodes (in this case it's DepthwiseConv2D). Currently the visualizer works for any properties that are tensors of shape [a, b...] (in this case [1, 3, 3, 32]):
image
So in order to see the visualizer:

  • we need a *.circle model that contains at least one node with tensor properties like 'weights', 'filter', etc. (Conv2D, for example).
  • open folder that contains such model
  • click on the model file in Explorer
  • click on such node (Conv2D)
  • in 'Node Properties' panel find 'Inputs' containing the tensor property ('filter' in case of Conv2D)
  • expand it with + button
  • the visualizer should appear

@seanshpark
Copy link
Contributor

Now I can see the bars :)

I've tried with some models and found this:

Model: inception_v3_2018_04_27.tgz

Image is black with this Conv2D
image

when selected with 0, 3
image

and when I change 3'rd value black bar disappears
image

@seanshpark
Copy link
Contributor

Q) How does the bar graph show when Tensor is 2D, 3D or 5D ?

@seanshpark
Copy link
Contributor

Q) what is the meaning of the colors ?

@staddy
Copy link
Contributor Author

staddy commented Feb 9, 2023

@seanshpark, thank you, the bug with black bar is fixed.

Q) How does the bar graph show when Tensor is 2D, 3D or 5D ?

If I understand your question right,

  • when Tensor is 2D, axes selector and values selector are not shown, all values of the Tensor are rendered as a 2D image
  • when Tensor is 3D, 4D, 5D ..., axes selector and values selector are shown and user has to select 2 axes with check boxes. The selected axes are used to iterate over (as if Tensor was 2D). For all other axes user has to select fixed values.
    For example, we have a 5D Tensor. User has selected 0 and 2 axes (with checkboxes), and selected fixed values 5, 13, 7 for the other 3 axes. So the values used for bar will be tensor[x][5][y][13][7], where x - all integers from 0 to length of axis 0, y - all integers from 0 to length of axis 2. So the resulting image pixel (17, 19) is the value tensor[17][5][19][13][7].

@staddy
Copy link
Contributor Author

staddy commented Feb 9, 2023

Q) what is the meaning of the colors ?

The higher wavelength, the higher value:

  • red = 1.0 (the highest value in tensor)
  • green = 0.5
  • blue = 0.0 (the lowest value in tensor)

'value' is from 0.0 to 1.0 (normalized value from tensor):

      value *= 2;
      let blue = Math.round(Math.max(0, 255 * (1.0 - value)));
      let red = Math.round(Math.max(0, 255 * (value - 1.0)));
      let green = 255 - blue - red;

@seanshpark
Copy link
Contributor

seanshpark commented Feb 9, 2023

The lower wavelength, the higher value:

thanks for the comment.
maybe some document may help understanding for later readers.

@seanshpark
Copy link
Contributor

If I understand your question right,

Yes I think so :)

I've tried with Add operator with input + constant but failed to see the color bars.
There seems some problem with attaching the files. so below is how to generate them.

If you can, please try
(1) code in Samsung/ONE, res/TensorFlowLiteRecipes/Add_002/test.recipe file
(2) Copy to Add_003 and edit it like

operand {
  name: "ifm1"
  type: FLOAT32
  shape { dim: 128 dim: 128 }
}
operand {
  name: "ifm2"
  type: FLOAT32
  shape { dim: 128 dim: 128 }
  filler {
    tag: "gaussian"
    arg: "0.0"
    arg: "1.0"
  }
}
operand {
  name: "ofm"
  type: FLOAT32
  shape { dim: 128 dim: 128 }
}
operation {
  type: "Add"
  input: "ifm1"
  input: "ifm2"
  output: "ofm"
  add_options {
    activation: NONE
  }
}
input: "ifm1"
output: "ofm"

(3) Copy to Add_004 and change shape to

shape { dim: 128 dim: 2 dim: 2 dim: 2 dim: 128 }

(4) build ONE

./nncc configure
./nncc build

(5) in build/compiler/common-artifacts folder there should be Add_003.circle and Add_004.circle
(6) open the second input, which should be a constant tensor

@staddy
Copy link
Contributor Author

staddy commented Feb 9, 2023

failed to see the color bars.

@seanshpark, strange,
image
image

@seanshpark
Copy link
Contributor

check on first axis 127 and last axis 127

@staddy
Copy link
Contributor Author

staddy commented Feb 9, 2023

check on first axis 127 and last axis 127

@seanshpark, sorry, still can't reproduce (though currently the width of text input is not enough to show 3 digits - so it's 12 instead of 127 on the screenshots):
image
image
image
Have you pulled my last fix (f619535)?

@seanshpark
Copy link
Contributor

Have you pulled my last fix

Latest commit is work OK :)

@staddy staddy force-pushed the visualization-draft branch 4 times, most recently from 43dc0ad to c31c81c Compare February 10, 2023 10:02
@staddy
Copy link
Contributor Author

staddy commented Feb 10, 2023

@seanshpark
Copy link
Contributor

seanshpark commented Feb 12, 2023

Docs are ready:

Thanks for the document!
As there are lots of image files, how about move them into new docs/images folder ?
Existing images maybe moved later.

Add: I would be better to rename VisualTensorView.jpg to something else.

@staddy
Copy link
Contributor Author

staddy commented Feb 13, 2023

@seanshpark, done

@seanshpark
Copy link
Contributor

Code looks good to me (not sure for others)
Can you please post to 3 PRs? (1) media files (2) src files and (3) doc files.

@staddy
Copy link
Contributor Author

staddy commented Feb 13, 2023

@seanshpark, done:
VisualTensorView implementation (disabled by default):
#1502
Enable VisualTensorView for Circle Graph only:
#1503
Documentation:
#1504

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.

None yet

2 participants