CSAILVision / NetDissect

Network Dissection http://netdissect.csail.mit.edu for quantifying interpretability of deep CNNs.
MIT License
449 stars 115 forks source link

Generating views fails due to missing files #7

Closed mlosch closed 6 years ago

mlosch commented 6 years ago

Running the default script script/rundissect_pytorch.sh fails for the generating view step with the following error traceback:

Writing imgmax ls: cannot access probes/pytorch_alexnet_imagenet/html/features.html: No such file or directory Generating views features Adding tallys of unit/label alignments. Generating html summary probes/pytorch_alexnet_imagenet/html-features.html Sorting units by score. Visualizing features unit 114 Traceback (most recent call last): File "src/viewprobe.py", line 429, in verbose=True) File "src/viewprobe.py", line 112, in generate_html_summary imsave(self.ed.filename(['html', imfn]), tiled) File ".../anaconda2/lib/python2.7/site-packages/scipy/misc/pilutil.py", line 199, in imsave im.save(name) File ".../anaconda2/lib/python2.7/site-packages/PIL/Image.py", line 1823, in save fp = builtins.open(filename, "w+b") IOError: [Errno 2] No such file or directory: 'probes/pytorch_alexnet_imagenet/html-image/features-0114.jpg'

The directory html-image does not even exist in the generated file structure. What does exist is: probes/pytorch_alexnet_imagenet/html/image. The last two directories are empty.

ruthcfong commented 6 years ago

I fixed this by changing src/viewprobe.py as follows:

diff --git a/src/viewprobe.py b/src/viewprobe.py
index 0e48b05..9b84e3d 100644
--- a/src/viewprobe.py
+++ b/src/viewprobe.py
@@ -109,13 +109,14 @@ class NetworkProbe:
                       col*(imsize+1):col*(imsize+1)+imsize,:] = vis
             imfn = 'image/%s%s-%04d.jpg' % (
                     expdir.fn_safe(layer), gridname, unit)
-            imsave(self.ed.filename(['html', imfn]), tiled)
+            #imsave(self.ed.filename(['html', imfn]), tiled)
+            imsave(self.ed.filename(os.path.join('html', imfn)), tiled)
             labels = '; '.join(['%s (%s, %f)' %
                     (name_pciou[c][unit], categories[c], score_pciou[c, unit])
                     for c in bestcat_pciou[:,unit]])
             html.extend([
                 '<h6>%s unit %d: %s</h6>' % (layer, unit + 1, labels),
-                '<img src="%s" height="%d">' % (imfn, imscale)
+                '<img src="%s" height="%d">' % (os.path.join('html', imfn), imscale)
                 ])
         html.extend([
             '</div>', '</body>', '</html>', ''])
mlosch commented 6 years ago

Thanks for commenting! It's not that I cannot fix it myself though. It would have been nice if it worked out of the box. I thus have opened this issue to give an incentive to fix the repository. Also I had to fix the same problem in all *.probe.py files.

zhoubolei commented 6 years ago

Thanks for reporting the issue @mlosch. I fixed the bug based on the suggestion given by @ruthcfong !