csailvision / netdissect-lite Goto Github PK
View Code? Open in Web Editor NEWLight version of Network Dissection for Quantifying Interpretability of Networks
Light version of Network Dissection for Quantifying Interpretability of Networks
It seems the repo is suffering from changes in Torch source code, more specifically in the use of the BatchNorm2d object put possibly on more places.
The repo works fine for the resnet18 model, but downloading and using the pretrained models for resnet50 and densenet161 yields errors:
AttributeError: 'BatchNorm2d' object has no attribute 'track_running_stats'
There are also a set of SourceChangeWarnings, among other:
/jet/var/python/lib/python3.6/site-packages/torch/serialization.py:425: SourceChangeWarning: source code of class 'torch.nn.modules.batchnorm.BatchNorm2d' has changed.
you can retrieve the original source code by accessing the object's source attribute or set torch.nn.Module.dump_patches = True and use the patch tool to revert the chang
es.
Tried running both Pytorch versions 0.5.0 and 1.0.0. This thread suggests downgrading Pytorch to 0.3 would make it work, will update if I get the possibility to do so.
Traceback (most recent call last):
File "main.py", line 11, in <module>
features, maxfeature = fo.feature_extraction(model=model)
File "/jet/prs/NetDissect-Lite/feature_operation.py", line 67, in feature_extraction
logit = model.forward(input_var)
File "/jet/var/python/lib/python3.6/site-packages/torchvision/models/densenet.py", line 157, in forward
features = self.features(x)
File "/jet/var/python/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "/jet/var/python/lib/python3.6/site-packages/torch/nn/modules/container.py", line 91, in forward
input = module(input)
File "/jet/var/python/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in __call__
result = self.forward(*input, **kwargs)
File "/jet/var/python/lib/python3.6/site-packages/torch/nn/modules/batchnorm.py", line 65, in forward
self.training or not self.track_running_stats,
File "/jet/var/python/lib/python3.6/site-packages/torch/nn/modules/module.py", line 518, in __getattr__
type(self).__name__, name))
AttributeError: 'BatchNorm2d' object has no attribute 'track_running_stats'
Running script/dlzoo_example.sh
no longer works, but gives the following error:
Connecting to places2.csail.mit.edu (places2.csail.mit.edu)|128.52.132.120|:80... failed: Connection refused.
Hi there, when I was downloading the BRODEN dataset as your instruction mentioned, I got "Connection refused" error. Neither can I visit the http://netdissect.csail.mit.edu project page for further information. Is there any other way to get these data and pre-trained models?
Thank you for your great work. However, when I ran the current code under python 3.11 and numpy 1.26, I got a very bad result. The magic is that when I run in another lower version (i.e. python 3.7 and numpy 1.21), the results are as expected.
I checked the code carefully and found that there was a problem on line 150 of data_loader.py:
"result[list(np.indices(arr.shape)) + [arr]] = 1"
This is because when doing one-hot encoding, the current code uses inappropriate slicing, which causes all one-hot encoding values to be set to 1 in the newer environment.
I recommend making the following changes to line 150 of data_loader.py:
"result[np.indices(arr.shape), np.array(arr)] = 1"
Unfortunately, I was not aware of this problem before, which resulted in an error in a previous job :(
I first ran "python main.py" command successfully with MODEL='resnet18' in the settings.py, which seems to indicate my environment works correctly.
Nest, I changed the settings.py to MODEL='resnet50' and encountered the following error:
Traceback (most recent call last):
File "main.py", line 8, in
model = loadmodel(hook_feature)
File "/media/sdb1/shenw/sandbox/netdissect/NetDissect-Lite/loader/model_loader.py", line 9, in loadmodel
checkpoint = torch.load(settings.MODEL_FILE)
File "/home/shenw/workspace/anaconda3/envs/pytorch-netdissect2/lib/python3.6/site-packages/torch/serialization.py", line 584, in load
with _open_file_like(f, 'rb') as opened_file:
File "/home/shenw/workspace/anaconda3/envs/pytorch-netdissect2/lib/python3.6/site-packages/torch/serialization.py", line 234, in _open_file_like
return _open_file(name_or_buffer, mode)
File "/home/shenw/workspace/anaconda3/envs/pytorch-netdissect2/lib/python3.6/site-packages/torch/serialization.py", line 215, in init
super(_open_file, self).init(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'zoo/whole_resnet50_places365_python36.pth.tar'
This error message seems to indicate that I didn't download the model file 'whole_resnet50_places365_python36.pth.tar'.
What is the fix for this error? Where can I find 'zoo/whole_resnet50_places365_python36.pth.tar' from your website?
Firstly thanks for publishing the code.
I want to use NetDissect-Lite for a model trained on cifar10. Can I use it for trained VGG for cifar10 32x32? If yes, is resizing the broaden dataset folder to 32x32 is sufficient? or I should only have a trained model on resized cifar10 to 227x227?
CSAILVision/NetDissect is licensed under the MIT license.
Could you please upload a license for this repository too?
Hi,
Thank you for making your codes available online.
I try running the main.py on resnet18. Specifying FEATURE_NAMES = ['layer4'] in the settings file, everything works well. However, when I change it to ['layer3'] and ['layer2'], the terminal shows 'Bus error' after printing the line 'extracting feature from batch 256 / 495' and 'extracting feature from batch 129 / 495', respectively, and then the process terminates.
Would you please suggest me how I can solve this issue? Thank you.
Best,
Peter
Hi,
Thanks for your contribution first!
I am trying to interpret my networks based on your method. However, it seems that the Broaden dataset is not available anymore. I cannot open the website http://netdissect.csail.mit.edu/ or download http://netdissect.csail.mit.edu/data/broden1_224.zip. Could you please update the link to your dataset?
Regards.
Could you please provide a License for NetDissect-Lite? Is the License the same as that of NetDissect?
Thank you!
Hi,
I've read your extended paper (https://arxiv.org/pdf/1711.05611.pdf) and reproduced your main results.
What I'm looking for is segmenting images using top activated units (section 3.10 and fig.27 in the paper). I don't think it has been implemented in this repo, but I guess it is in the original NetDissect?
If it has been implemented, could you give me the link to where it's uploaded (compatible with PyTorch would be best)? Or else, do you have ideas on how to efficiently code it?
This line throws an NameError on every file found in the line above so the expected os.remove() never happens. The loop is placing filepaths into the variable c but the os.remove() is attempting to delete filepath f which is an undefined name which raises NameError which is swept under the rug by the bare exception. PEP8 and other sources are quite articulate why bare exceptions should be avoided and this is a classic example.
flake8 testing of https://github.com/CSAILVision/NetDissect-Lite on Python 3.7.1
$ flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
./visualize/expdir.py:81:27: F821 undefined name 'f'
os.remove(f)
^
1 F821 undefined name 'f'
1
I just run the main.py in WIN10 system, and fix the scipy.misc problem by change import and sentence
As I know ,Windows don't support multiprocessing,
So what I modify in the setting.py are
WORKERS = 0
Got error like this:
Traceback (most recent call last):
File "D:/1.Study/Jupyter Book/interpretable-ai-book-master/Chapter_06/NetDissect-Lite/main.py", line 11, in
features, maxfeature = fo.feature_extraction(model=model)
File "D:\1.Study\Jupyter Book\interpretable-ai-book-master\Chapter_06\NetDissect-Lite\feature_operation.py", line 58, in feature_extraction
for batch_idx,batch in enumerate(loader.tensor_batches(bgr_mean=self.mean)):
File "D:\1.Study\Jupyter Book\interpretable-ai-book-master\Chapter_06\NetDissect-Lite\loader\data_loader.py", line 542, in tensor_batches
batch = self.fetch_tensor_batch(
File "D:\1.Study\Jupyter Book\interpretable-ai-book-master\Chapter_06\NetDissect-Lite\loader\data_loader.py", line 536, in fetch_tensor_batch
batch = self.fetch_batch()
File "D:\1.Study\Jupyter Book\interpretable-ai-book-master\Chapter_06\NetDissect-Lite\loader\data_loader.py", line 528, in fetch_batch
return result.get(31536000)
File "D:\Software\anaconda3\lib\multiprocessing\pool.py", line 765, in get
self.wait(timeout)
File "D:\Software\anaconda3\lib\multiprocessing\pool.py", line 762, in wait
self._event.wait(timeout)
File "D:\Software\anaconda3\lib\threading.py", line 558, in wait
signaled = self._cond.wait(timeout)
File "D:\Software\anaconda3\lib\threading.py", line 306, in wait
gotit = waiter.acquire(True, timeout)
OverflowError: timeout value is too large
file missing, loading from scratch
Other question from me:
1.Is Win10 system possible to run the code(No multiprocessing and only has single GPU)?
2.Can scipy.misc problem be fixed by change the sentence as below:
imread:
from scipy.misc import imread->import imageio
imread->imageio.imread
imsave:
from scipy.misc import imsave->import cv2 as cv
imsave->cv.imsave
imresize:
from scipy.misc import imresize->from PIL import Image
imresize(,)->np.array(Image.fromarray(arr).resize((,)))
Please help me with it ,thanks!
How can I identify a concept in an image? I want to debug the dataset to understand the concepts labelled for each image, but I couldn't find a simple way.
I know that the CSV files in the dataset folder index for each image and its concepts (part, object, etc.). But I couldn't find a way to see the label concept in an image; for example, I'd like to know which image has the wheel part concept. Can I identify this using only the CSV files? If not, could you tell me where in the code can I extract this information?
Disclaimer: I did not go through all the code yet, plus not familiar with thread manipulation and such in python, and I did not run the code yet (some compatibility mishaps to correct with scipy.misc for imresize in the latest version of the libs and checking the code including the file manipulation still hold me from doing so).
Changed:
from PIL import Image
# mask = imresize(feature_map, (concept_map['sh'], concept_map['sw']), mode='F')
mask = np.array(Image.fromarray(feature_map).resize((concept_map['sh'], concept_map['sw'])))
(Did not run that version, so maybe it is breaking the code or buggy)
There seems to be a typo in that line:
NetDissect-Lite/loader/data_loader.py
Line 593 in 2163454
Then, without any understanding of the underlying program but with pylint, not sure if 'cancel_join_thread' can work on a pool, 'result' would appear compatible type-wise (as in the pytorch code for worker it was applied on data_queue), but not even sure if it makes any sense (plus initially outside of the loop, so probably not meant for 'result').
Hi,
I tried to run the code and see the result in a 16 Gb GPU memory machine.
But it shows:
...
Processing quantile index 63296: 758.747045 2169.666316
Exceeded job memory limit
and stops.
Can I ask the memory requirement of the program?
Thank you.
Jimmy
if someone studying the explainable ai ,may we have a comunication? wechat 15071380462,in china mainland
I find the default dataset 'broden' with some '*.csv'. If I need to use another dataset, What should I do?
I modify the settings.py (MODEL = 'densenet161') and download the whole_densenet161_places365_python36.pth.tar. And run 'main.py' import errors as below:
AttributeError: 'BatchNorm2d' object has no attribute 'track_running_stats'
I ran "python main.py" and I got:
labelprobe image index 63296, items per sec 99.2679, 126.2880
Traceback (most recent call last):
File "/home/jenazads/github/NetDissect-Lite/loader/data_loader.py", line 518, in batches
raise StopIteration
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "main.py", line 18, in
tally_result = fo.tally(features[layer_id],thresholds,savepath="tally.csv")
File "/home/jenazads/github/NetDissect-Lite/feature_operation.py", line 216, in tally
FeatureOperator.tally_job((features, self.data, threshold, tally_labels, tally_units, tally_units_cat, tally_both, 0, self.data.size()))
File "/home/jenazads/github/NetDissect-Lite/feature_operation.py", line 142, in tally_job
for batch in pd.batches():
RuntimeError: generator raised StopIteration
I identify that it happens in the feature_operation.py when batch is None.
What should I do? or do you know what is happening??
Hi when I try to import netdissect I get the following error:
ImportError: cannot import name 'imread' from 'scipy.misc' (/usr/local/lib/python3.10/dist-packages/scipy/misc/init.py)
Has anyone encountered this before? And what was your way around it?
I trained a VGG-16 for CIFAR10, 32x32 pixels. When I run netdissect for different Conv layers, e.g. conv1 and conv13, I got the same results. Should it be like this?
I got the same results for both :
(['grass', 'sky', 'zigzagged', 'striped', 'chequered', 'banded', 'waffled', 'freckled', 'red-c', 'blue-c'], [1, 1, 19, 14, 14, 10, 1, 1, 1, 1], [('object', 2), ('scene', 0), ('part', 0), ('material', 0), ('texture', 6), ('color', 2)], 100, 12, True, 'result/pytorch_vgg16_cifar10/html/image/conv1-bargraph.svg')
File "NetDissect-Lite-master/NetDissect-Lite-master/visualize/bargraph.py", line 111, in make_svg_bargraph
unitheight = float(barheight)/max(heights)
ValueError : max() arg is an empty sequence
I downloaded dataset and run the code but there is no heights value. Can you help me?
as i just can download resnet18 trained on places365, i want use more model to do some compare work. could you please provied more url for download model? very thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.