albermax / albermax/innvestigate

TypeError: 'function' object is not an iterator --- when using PatternComputer.compute_generator()

未關閉
#149 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
1.3k
分支
230
PR 合併指標
30 天內沒有已合併 PR

描述

Hi, I am facing an error when trying to compute patterns with `compute_generator()`:
`TypeError: 'function' object is not an iterator`
(See my code snippet below.)
I couldn't find a solution for quite some time now :/ I am guessing that `compute_generator()` is not happy with the `pattern_comp_generator`-object. On the other hand that object is of type ``... which is an iterator - and from the tracebacks I can not read out _which_ "'function' object" is not an iterator...

## My code snippet:

### imports
```
import keras
from keras.preprocessing import image
import innvestigate
import innvestigate.utils as iutils
```

### load and prepare a model
(used a simple relu CNN which was defined with keras' functional api)
```
model = keras.models.load_model('./my_model.hdf5')
model_wo_softmax = iutils.keras.graph.model_wo_softmax(model)
```

### data generator
(in the folder './data/train/' there is a folder for each class with the according .jpg images in it.)
```
def preprocess_input(x):
return x/255
pattern_comp_datagen = image.ImageDataGenerator(preprocessing_function=preprocess_input)
pattern_comp_generator = pattern_comp_datagen.flow_from_directory('./data/train/',
target_size=(28,28),
color_mode='rgb',
batch_size=32,
class_mode='categorical',
shuffle=True
)
```

### compute pattern
```
pattern_comp = innvestigate.tools.pattern.PatternComputer(model_wo_softmax,
pattern_type='relu')
patterns = pattern_comp.compute_generator(pattern_comp_generator,
steps_per_epoch=1500,
verbose=1)
```

貢獻指南

這個儲存庫沒有索引到貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。