albermax / innvestigate

A toolbox to iNNvestigate neural networks' predictions!
Other
1.25k stars 233 forks source link

KeyError: '--' when trying to recreate imagenet_compare_networks.ipynb #183

Closed sirnyls closed 3 years ago

sirnyls commented 4 years ago

When I start running the analyses, I get the output "Creating analyses for network vgg16", but then comes the KeyError '--' for line 24: text.append(("%s" % label_to_class_name[y],

enryH commented 4 years ago

Do you use TF1 or the TF2?

sirnyls commented 4 years ago

1.15.0

enryH commented 4 years ago

It says it's tested with 1.12, but it might also work with 1.13 or 1.14. (I set up a test later to see what works)

enryH commented 4 years ago

Your are right, I did not see that you are referring to imagenet_compare_networks.ipynb.

So the key -- is assigned by a function called get_class which should load the images, and is supposed to indicate picking a random image, but here we need a specific one.

On the way I found that other examples are also not running... I myself never run all examples, so it could be a nice exercise.

enryH commented 3 years ago

So the problem is that the image loading function in examples/utils.py loads all jpg images from examples/images/ and assumes they all have class labels in their name. Images not from ImageNet2012 dataset get the missing key tag --. I guess the easiest way is to check directly for a non-default class label when loading the images.

images = [(load_image(os.path.join(base_dir, "images", f), size),
                 get_class(f))
                 for f in os.listdir(os.path.join(base_dir, "images"))
                 if (f.lower().endswith(".jpg") or f.lower().endswith(".jpeg")) and get_class(f) != "--"]

See commit