idiap / importance-sampling

Code for experiments regarding importance sampling for training neural networks
Other
320 stars 60 forks source link

RuntimeError: The layer has never been called and thus has no defined output shape. #32

Open jaesunghwang opened 3 years ago

jaesunghwang commented 3 years ago

when i run "python examples/mnist_cnn.py" according to "https://www.idiap.ch/~katharas/importance-sampling/examples/", but i have errors like below. (cf, python examples/mnist_cnn.py --uniform, it is ok)

Do you have any idea to fix it?

============================== Traceback (most recent call last): File "examples/mnist_cnn.py", line 67, in wrapped = ConstantTimeImportanceTraining(model) File "C:\Users\danie\AppData\Roaming\Python\Python37\site-packages\importance_sampling\training.py", line 444, in init layer File "C:\Users\danie\AppData\Roaming\Python\Python37\site-packages\importance_sampling\training.py", line 340, in init super(_UnbiasedImportanceTraining, self).init(model, score, layer) File "C:\Users\danie\AppData\Roaming\Python\Python37\site-packages\importance_sampling\training.py", line 39, in init layer=layer File "C:\Users\danie\AppData\Roaming\Python\Python37\site-packages\importance_sampling\model_wrappers.py", line 169, in init self._augment_model(model, score, reweighting) File "C:\Users\danie\AppData\Roaming\Python\Python37\site-packages\importance_sampling\model_wrappers.py", line 205, in _augment_model output_shape = model.get_output_shape_at(0)[1:] File "C:\Users\danie\anaconda3\envs\importance-sampling\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 2030, in get_output_shape_at 'output shape') File "C:\Users\danie\anaconda3\envs\importance-sampling\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 2603, in _get_node_attribute_at_index 'and thus has no defined ' + attr_name + '.') RuntimeError: The layer has never been called and thus has no defined output shape.

angeloskath commented 3 years ago

Hi, do you mind sharing the TF and keras versions that you are using? Also, you could try to use an older version from around the time that the library was released.

Cheers, Angelos

jaesunghwang commented 3 years ago

i use TF v2.3.1 and keras v2.4.3. could you share your version of these ?

angeloskath commented 3 years ago

It has been a long time since I tested the code and in general tensorflow 2 is not supported. You can also see issue #25 for more details.

I would suggest TF 1.13.1 and keras 2.0.0 for testing purposes but you might even get it working with TF 2.1 and keras 2.3.1 .

jaesunghwang commented 3 years ago

ok, thanks your answer and link. i tried to downgrade TF and others. i will reset all setting, restart on your suggestion version. i will re-visit to write the result, soon.

ibarrien commented 3 years ago

Hi, if useful, I got an mnist example to almost work with: tensorflow==2.3.1 keras==2.3.1

Still get an error though:

score = model.evaluate(x_test, y_test, verbose=0) tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'input_1' with dtype float and shape [?,10]

ibarrien commented 3 years ago

Alright, I finally got it to work! tensorflow==1.13.1 keras==2.2.4

Specifically, /examples/mnist_mlp.py with args.importance_training=True.

With tensorflow 1.3.1, was not able to install the above-suggested keras 2.0.0 since "seqeval 0.0.12 requires Keras>=2.2.4, but you have keras 2.0.0 which is incompatible."