bethgelab / foolbox

A Python toolbox to create adversarial examples that fool neural networks in PyTorch, TensorFlow, and JAX
https://foolbox.jonasrauber.de
MIT License
2.78k stars 426 forks source link

Issues when passing multi-output model as argument #608

Open VasylKor opened 3 years ago

VasylKor commented 3 years ago

Hi there, I got this error whenever I pass my model (converted in a foolbox model) as argument in accuracy() or attack().

/usr/local/lib/python3.6/dist-packages/foolbox/utils.py in accuracy(***failed resolving arguments***)
     13     del inputs, labels
     14 
---> 15     predictions = fmodel(inputs_).argmax(axis=-1)
     16     accuracy = (predictions == labels_).float32().mean()
     17     return accuracy.item()

/usr/local/lib/python3.6/dist-packages/foolbox/models/base.py in __call__(self, inputs)
    100         x, restore_type = ep.astensor_(inputs)
    101         y = self._preprocess(x)
--> 102         z = ep.astensor(self._model(y.raw))
    103         return restore_type(z)
    104 

/usr/local/lib/python3.6/dist-packages/eagerpy/astensor.py in astensor(x)
     52     if name == "numpy" and isinstance(x, m[name].ndarray):  # type: ignore
     53         return NumPyTensor(x)
---> 54     raise ValueError(f"Unknown type: {type(x)}")
     55 
     56 

ValueError: Unknown type: <class 'list'>

It's worth mentioning that my Keras model is not Sequential and has multiple outputs. When reducing the model output to one it goes without issues. Is that multi-output models must be set up differently or they are just not supported?

karthikiitm87 commented 3 months ago

HI @VasylKor did you find the solution for this?

matt-sharp commented 1 month ago

Keen to know the answer also @VasylKor . I'm trying to use YOLOv7 which outputs a tuple and produces the same error.

VasylKor commented 1 month ago

Hi @matt-sharp, @karthikiitm87. Alas, I could not find the solution. After a week or so I ended up (badly) reinventing the wheel.