keras-surgeon icon indicating copy to clipboard operation
keras-surgeon copied to clipboard

get_apoz throws when passing np.ndarray as x_val.

Open gchlebus opened this issue 5 years ago • 2 comments

https://github.com/BenWhetton/keras-surgeon/blob/459e8dfcd9606a35299468a5e9c18b27453d3cfb/src/kerassurgeon/identify.py#L63

The following exception is thrown by the above line: AttributeError: 'numpy.ndarray' object has no attribute 'n'

gchlebus avatar Nov 29 '18 12:11 gchlebus

You can clone from https://github.com/MrMimic/keras-surgeon, beug's corrected here. I pulled request the OP.

MrMimic avatar Dec 07 '18 11:12 MrMimic

Add to imports:

from keras.preprocessing.image import ImageDataGenerator

Change:

if hasattr(x_val, "__iter__"):
            temp_model = Model(model.inputs,
                               act_layer.get_output_at(act_index))
            a = temp_model.predict_generator(
                x_val, x_val.n // x_val.batch_size)

to

if hasattr(x_val, "__iter__"):
            temp_model = Model(model.inputs,
                               act_layer.get_output_at(act_index))
            datagen = ImageDataGenerator(rescale=1./255)
            a = temp_model.predict_generator(
                datagen.flow(x_val, batch_size=bs),
                steps=x_val.shape[0] // bs)

where bs is passed as a function parameter in:

def get_apoz(model, layer, x_val, bs, node_indices=None):

pjd-ds avatar Jul 24 '19 00:07 pjd-ds