range(len(images))
with enumerate(images)
387 gcam.backward(ids=ids[:, [i]])
388 regions = gcam.generate(target_layer=args.target_layer)
389
390 for j in range(len(images)):391 print("\t#{}: {} ({:.5f})".format(j, classes[ids[j, i]], probs[j, i]))
392
393 # Guided Backpropagation
Using range(len(...))
is not pythonic. Python does not have not index-based loops. Instead, it uses collection iterators.
Python has a built-in method enumerate
which adds a counter to an iterable.
Using this, you can access the counter and the value from the iterable at the same time.
It is therefore recommended to replace range(len(...))
with enumerate(...)
.
for index in range(len(mylist)):
...
for index, element in enumerate(mylist):
...