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

Whether is possible to customize the CNN-Explainer #9

Closed
ljjsfe opened this issue May 7, 2020 · 5 comments
Closed

Whether is possible to customize the CNN-Explainer #9

ljjsfe opened this issue May 7, 2020 · 5 comments

Comments

@ljjsfe
Copy link

ljjsfe commented May 7, 2020

Hi.

Thank you for sharing this excellent work. The explainer is super helpful for understanding the CNN.
Since I am not familiar with the TF.js. I wonder if I finetune the tiny-VGG on other datasets for example dog vs cat, will explainer automatically change to show how the CNN works on dog vs cat? Or I have to rewrite the part of the js to make it works. Thank you.

@xiaohk
Copy link
Member

xiaohk commented May 7, 2020

Good question :)

Unfortunately, you would need to change some javascript code if you fine-tune the underlying model to other classes. It would be very straightforward though, if you are using our tiny-VGG architecture (with 10 output classes).

Let me know if you are interested in trying out; I can give you some pointers to the functions you might need to change. I will close this issue for now.

@ljjsfe
Copy link
Author

ljjsfe commented May 8, 2020

Sorry for duplicate the question. I thought I forget to submit it. :) I am interested in trying out to modify the functions. Can you point me the functions? Thx,

@xiaohk
Copy link
Member

xiaohk commented May 11, 2020

Sure! You can change the output class labels here:

classLists: ['lifeboat', 'ladybug', 'pizza', 'bell pepper', 'school bus',
'koala', 'espresso', 'red panda', 'orange', 'sport car']

It matches the order of your output labels in your tiny-vgg model. If you are using 10 class, then changing the line above should be good to go. If you are using other number of classes, then here are some functions you want to look into:

nodeGroups.append('rect')
.attr('class', 'output-rect')
.attr('x', left)
.attr('y', (d, i) => nodeCoordinate[l][i].y + nodeLength / 2 + 8)
.attr('height', nodeLength / 4)
.attr('width', 0)
.style('fill', 'gray');
nodeGroups.append('text')
.attr('class', 'output-text')
.attr('x', left)
.attr('y', (d, i) => nodeCoordinate[l][i].y + nodeLength / 2)
.style('dominant-baseline', 'middle')
.style('font-size', '11px')
.style('fill', 'black')
.style('opacity', 0.5)
.text((d, i) => classLists[i]);

svg.selectAll('g.node-output').each(
(d, i, g) => drawOutputScore(d, i, g, outputRectScale)
);

/**
* Draw bar chart to encode the output value
* @param {object} d d3 data
* @param {index} i d3 data index
* @param {[object]} g d3 group
* @param {function} scale map value to length
*/
const drawOutputScore = (d, i, g, scale) => {
let group = d3.select(g[i]);
group.select('rect.output-rect')
.transition('output')
.delay(500)
.duration(800)
.ease(d3.easeCubicIn)
.attr('width', scale(d.output))
}

Keep me updated when you are trying out new classes. I'm happy to help :)

@ljjsfe
Copy link
Author

ljjsfe commented May 16, 2020 via email

@xiaohk
Copy link
Member

xiaohk commented Jun 9, 2020

A user has successfully adapted CNN Explainer to other dataset in #14 .

You can see their public GitHub page and code repository.

Hopefully you find these pointers helpful :)

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

No branches or pull requests

2 participants