Skip to content
This repository has been archived by the owner on Mar 2, 2020. It is now read-only.

TypeError: Too many parameter passed to theano function #11

Open
nwoeanhinnogaehr opened this issue Nov 23, 2016 · 4 comments
Open

TypeError: Too many parameter passed to theano function #11

nwoeanhinnogaehr opened this issue Nov 23, 2016 · 4 comments

Comments

@nwoeanhinnogaehr
Copy link

I'm getting the following error immediately after the first epoch completes. Any idea what the problem might be?

The shape of my inputs is (3, 256, 256).

Epoch 1/5
2976/3000 [============================>.] - ETA: 0s - loss: 0.1243 - acc: 0.9458Traceback (most recent call last):
  File "learn.py", line 36, in <module>
    batch_size=32)
  File "/home/nweninge/.local/lib/python2.7/site-packages/aetros/KerasIntegration.py", line 55, in overwritten_fit
    class_weight, sample_weight, **kwargs)
  File "/home/nweninge/.local/lib/python2.7/site-packages/keras/engine/training.py", line 1124, in fit
    callback_metrics=callback_metrics)
  File "/home/nweninge/.local/lib/python2.7/site-packages/keras/engine/training.py", line 862, in _fit_loop
    callbacks.on_epoch_end(epoch, epoch_logs)
  File "/home/nweninge/.local/lib/python2.7/site-packages/keras/callbacks.py", line 42, in on_epoch_end
    callback.on_epoch_end(epoch, logs)
  File "/home/nweninge/.local/lib/python2.7/site-packages/aetros/KerasLogger.py", line 218, in on_epoch_end
    images = self.build_insight_images()
  File "/home/nweninge/.local/lib/python2.7/site-packages/aetros/KerasLogger.py", line 300, in build_insight_images
    Y = fn(input_data_x_sample)[0]
  File "/home/nweninge/.local/lib/python2.7/site-packages/keras/backend/theano_backend.py", line 792, in __call__
    return self.function(*inputs)
  File "/usr/local/lib/python2.7/dist-packages/theano/compile/function_module.py", line 770, in __call__
    raise TypeError("Too many parameter passed to theano function")
TypeError: Too many parameter passed to theano function```
@gabrieldemarmiesse
Copy link

I had this bug too.
The strange thing is that, I tried to run my script without "KerasIntegration('gabrieldemarmiesse/test', model, insights = True)" and it worked fine so I guess the bug comes from either aetros, keras or theano. For more information, here is my script:

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.optimizers import SGD
import numpy as np
from aetros.KerasIntegration import KerasIntegration
import os

os.environ['API_KEY'] = "my api key"

data_dim = 20
nb_classes = 4

model = Sequential()

# Dense(64) is a fully-connected layer with 64 hidden units.
# in the first layer, you must specify the expected input data shape:
# here, 20-dimensional vectors.
model.add(Dense(64, input_dim=data_dim, init='uniform'))
model.add(Activation('tanh'))
model.add(Dropout(0.5))
model.add(Dense(64, init='uniform'))
model.add(Activation('tanh'))
model.add(Dropout(0.5))
model.add(Dense(nb_classes, init='uniform'))
model.add(Activation('softmax'))

model.compile(loss='categorical_crossentropy',
              optimizer='sgd',  
              metrics=["accuracy"])

# generate dummy training data
x_train = np.random.random((1000, data_dim))
y_train = np.random.random((1000, nb_classes))

# generate dummy test data
x_test = np.random.random((100, data_dim))
y_test = np.random.random((100, nb_classes))

KerasIntegration('gabrieldemarmiesse/test', model, insights = True )

model.fit(x_train, y_train,
          nb_epoch=200,
          batch_size=5)

score = model.evaluate(x_test, y_test, batch_size=16)

and here is the stacktrace:

C:\Users\smith>python y.py
Using Theano backend.
Training status changed to TRAINING
Training status changed to TRAINING
Epoch 1/200
 990/1000 [============================>.] - ETA: 0s - loss: 2.7636 - acc: 0.2444Traceback (most recent call last):
  File "y.py", line 43, in <module>
    batch_size=5)
  File "C:\Program Files\Anaconda3\lib\site-packages\aetros\KerasIntegration.py", line 55, in overwritten_fit
    class_weight, sample_weight, **kwargs)
  File "C:\Program Files\Anaconda3\lib\site-packages\keras\keras\models.py", line 652, in fit
    sample_weight=sample_weight)
  File "C:\Program Files\Anaconda3\lib\site-packages\keras\keras\engine\training.py", line 1111, in fit
    initial_epoch=initial_epoch)
  File "C:\Program Files\Anaconda3\lib\site-packages\keras\keras\engine\training.py", line 846, in _fit_loop
    callbacks.on_epoch_end(epoch, epoch_logs)
  File "C:\Program Files\Anaconda3\lib\site-packages\keras\keras\callbacks.py", line 43, in on_epoch_end
    callback.on_epoch_end(epoch, logs)
  File "C:\Program Files\Anaconda3\lib\site-packages\aetros\KerasLogger.py", line 218, in on_epoch_end
    images = self.build_insight_images()
  File "C:\Program Files\Anaconda3\lib\site-packages\aetros\KerasLogger.py", line 326, in build_insight_images
    Y = fn(input_data_x_sample)[0]
  File "C:\Program Files\Anaconda3\lib\site-packages\keras\keras\backend\theano_backend.py", line 811, in __call__
    return self.function(*inputs)
  File "C:\Program Files\Anaconda3\lib\site-packages\theano\theano\compile\function_module.py", line 772, in __call__
    raise TypeError("Too many parameter passed to theano function")
TypeError: Too many parameter passed to theano function

My system:
windows 10
Anaconda with python 3 (latest version right now)
keras (latest version right now)
Theano (latest version right now)
I'm working on a CPU. Cuda is not installed.

Here is the content of the .theanorc file:

[global]
floatX = float32
device = cpu

[nvcc]
compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin

and here is the content of the .keras/keras.json file:

{
    "floatx": "float32",
    "epsilon": 1e-07,
    "image_dim_ordering": "th",
    "backend": "theano"
}

Thank you.

@nwoeanhinnogaehr
Copy link
Author

I think the issue might be that no validation data was passed to model.fit().

Try setting either validation_data or validation_split.

@gabrieldemarmiesse
Copy link

I changed my code and added the validation_split parameter. Here is the result:

Training status changed to TRAINING
0.00GB GPU memory used of 0.00GB, GeForce GTX 970, device id 0
Train on 900 samples, validate on 100 samples
Training status changed to TRAINING
Epoch 1/200
870/900 [============================>.] - ETA: 0s - loss: 2.7474 - acc: 0.2609Traceback (most recent call last):
  File "C:\Program Files\Anaconda3\lib\site-packages\PIL\ImageFile.py", line 466, in _save
    fh = fp.fileno()
io.UnsupportedOperation: fileno

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "C:\Program Files\Anaconda3\lib\site-packages\aetros-0.3.5-py3.5.egg\aetros\KerasIntegration.py", line 55, in overwritten_fit
    class_weight, sample_weight, **kwargs)
  File "C:\Program Files\Anaconda3\lib\site-packages\keras\keras\models.py", line 652, in fit
    sample_weight=sample_weight)
  File "C:\Program Files\Anaconda3\lib\site-packages\keras\keras\engine\training.py", line 1113, in fit
    initial_epoch=initial_epoch)
  File "C:\Program Files\Anaconda3\lib\site-packages\keras\keras\engine\training.py", line 848, in _fit_loop
    callbacks.on_epoch_end(epoch, epoch_logs)
  File "C:\Program Files\Anaconda3\lib\site-packages\keras\keras\callbacks.py", line 45, in on_epoch_end
    callback.on_epoch_end(epoch, logs)
  File "C:\Program Files\Anaconda3\lib\site-packages\aetros-0.3.5-py3.5.egg\aetros\KerasLogger.py", line 218, in on_epoch_end
    images = self.build_insight_images()
  File "C:\Program Files\Anaconda3\lib\site-packages\aetros-0.3.5-py3.5.egg\aetros\KerasLogger.py", line 341, in build_insight_images
    'image': self.to_base64(image)
  File "C:\Program Files\Anaconda3\lib\site-packages\aetros-0.3.5-py3.5.egg\aetros\KerasLogger.py", line 469, in to_base64
    image.save(buffer, format="JPEG", optimize=True, quality=80)
  File "C:\Program Files\Anaconda3\lib\site-packages\PIL\Image.py", line 1698, in save
    save_handler(self, fp, filename)
  File "C:\Program Files\Anaconda3\lib\site-packages\PIL\JpegImagePlugin.py", line 725, in _save
    ImageFile._save(im, fp, [("jpeg", (0, 0)+im.size, 0, rawmode)], bufsize)
  File "C:\Program Files\Anaconda3\lib\site-packages\PIL\ImageFile.py", line 481, in _save
    fp.write(d)
TypeError: string argument expected, got 'bytes'

Maybe it's because insights=True only work with images and that this script is not using images?

@marcj
Copy link
Member

marcj commented Jan 25, 2017

Insights works currently only with images as input. This is a rather soft limitation that will be removed once we touch this functionality again.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants