coxlab / prednet

Code and models accompanying "Deep Predictive Coding Networks for Video Prediction and Unsupervised Learning"
https://arxiv.org/abs/1605.08104
MIT License
764 stars 260 forks source link

kitti_train.py cannot initialize weights from downloaded data #18

Closed arvoelke closed 7 years ago

arvoelke commented 7 years ago

Hi, I am currently trying to run your model using Python 2.7 and Theano==0.9.0 (using a GPU with pygpu==0.6.2). I am skipping the first step (by executing download_data.sh) and going straight to training (python kitti_train.py).

I initially tried using keras==2.0.2, but saw this error:

Traceback (most recent call last):
  File "kitti_train.py", line 59, in <module>
    errors = prednet(inputs)  # errors will be (batch_size, nt, nb_layers)
  File "/home/arvoelke/.virtualenvs/CTN/local/lib/python2.7/site-packages/keras/layers/recurrent.py", line 252, in __call__
    return super(Recurrent, self).__call__(inputs, **kwargs)
  File "/home/arvoelke/.virtualenvs/CTN/local/lib/python2.7/site-packages/keras/engine/topology.py", line 528, in __call__
    self.build(input_shapes[0])
  File "/home/arvoelke/prednet/prednet.py", line 216, in build
    if self.initial_weights is not None:
AttributeError: 'PredNet' object has no attribute 'initial_weights'

Then I noticed you suggest keras==1.2.0, so I downgraded, and retried, but saw a different error:

python kitti_train.py
Using Theano backend.
Can not use cuDNN on context None: Device not supported
Mapped name None to device cuda: Tesla C2075 (0000:02:00.0)
Traceback (most recent call last):
  File "kitti_train.py", line 60, in <module>
    errors_by_time = TimeDistributed(Dense(1, weights=[layer_loss_weights, np.zeros(1)], trainable=False), trainable=False)(errors)  # calculate weighted error by layer
  File "/home/arvoelke/.virtualenvs/CTN/local/lib/python2.7/site-packages/keras/engine/topology.py", line 543, in __call__
    self.build(input_shapes[0])
  File "/home/arvoelke/.virtualenvs/CTN/local/lib/python2.7/site-packages/keras/layers/wrappers.py", line 98, in build
    self.layer.build(child_input_shape)
  File "/home/arvoelke/.virtualenvs/CTN/local/lib/python2.7/site-packages/keras/layers/core.py", line 763, in build
    self.set_weights(self.initial_weights)
  File "/home/arvoelke/.virtualenvs/CTN/local/lib/python2.7/site-packages/keras/engine/topology.py", line 966, in set_weights
    str(weights)[:50] + '...')
ValueError: You called `set_weights(weights)` on layer "dense_1" with a  weight list of length 2, but the layer was expecting 0 weights. Provided weights: [array([[ 1.],
       [ 0.],
       [ 0.],
       ...

Any tips for things I could try? Thanks, Aaron

arvoelke commented 7 years ago

I downgraded even further to keras==1.0.8, and now it seems to be working. This version should probably be suggested in the README?

bill-lotter commented 7 years ago

Hi, sorry about the versioning trouble. I'm going to try to make it compatible with Keras 2.0 now, so all of this might be moot point, but it looks like I was using Keras 1.2.0 a few commits ahead of the official 1.2.0 release (specifically I was on 3a7cd05b488e327c1adccaaff10c78390d53b5a8) and it worked on that commit and 1.0.8 but not on the official 1.2.0 commit in-between. Sorry about that! Keras 2.0 is supposed to be stable release, so hopefully there won't be these issues in the future once I finish the upgrade.

dendisuhubdy commented 7 years ago

@arvoelke got the same error here, I'm trying your solution to downgrade Keras

(lisa) suhubdyd@grok-machine:~/research/prednet$ python kitti_train.py 
Using Theano backend.
Using cuDNN version 5105 on context None
Mapped name None to device cuda: GeForce GTX 750 (0000:01:00.0)
/u/suhubdyd/research/prednet/prednet.py:187: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(3, (3, 3), padding="same", activation=<function ..., data_format="channels_last")`
  self.conv_layers[c].append(Convolution2D(self.R_stack_sizes[l], self.R_filt_sizes[l], self.R_filt_sizes[l], border_mode='same', activation=act, dim_ordering=self.dim_ordering))
/u/suhubdyd/research/prednet/prednet.py:190: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(3, (3, 3), padding="same", activation="relu", data_format="channels_last")`
  self.conv_layers['ahat'].append(Convolution2D(self.stack_sizes[l], self.Ahat_filt_sizes[l], self.Ahat_filt_sizes[l], border_mode='same', activation=act, dim_ordering=self.dim_ordering))
/u/suhubdyd/research/prednet/prednet.py:193: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(48, (3, 3), padding="same", activation=<function ..., data_format="channels_last")`
  self.conv_layers['a'].append(Convolution2D(self.stack_sizes[l+1], self.A_filt_sizes[l], self.A_filt_sizes[l], border_mode='same', activation=self.A_activation, dim_ordering=self.dim_ordering))
/u/suhubdyd/research/prednet/prednet.py:187: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(48, (3, 3), padding="same", activation=<function ..., data_format="channels_last")`
  self.conv_layers[c].append(Convolution2D(self.R_stack_sizes[l], self.R_filt_sizes[l], self.R_filt_sizes[l], border_mode='same', activation=act, dim_ordering=self.dim_ordering))
/u/suhubdyd/research/prednet/prednet.py:190: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(48, (3, 3), padding="same", activation=<function ..., data_format="channels_last")`
  self.conv_layers['ahat'].append(Convolution2D(self.stack_sizes[l], self.Ahat_filt_sizes[l], self.Ahat_filt_sizes[l], border_mode='same', activation=act, dim_ordering=self.dim_ordering))
/u/suhubdyd/research/prednet/prednet.py:193: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(96, (3, 3), padding="same", activation=<function ..., data_format="channels_last")`
  self.conv_layers['a'].append(Convolution2D(self.stack_sizes[l+1], self.A_filt_sizes[l], self.A_filt_sizes[l], border_mode='same', activation=self.A_activation, dim_ordering=self.dim_ordering))
/u/suhubdyd/research/prednet/prednet.py:187: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(96, (3, 3), padding="same", activation=<function ..., data_format="channels_last")`
  self.conv_layers[c].append(Convolution2D(self.R_stack_sizes[l], self.R_filt_sizes[l], self.R_filt_sizes[l], border_mode='same', activation=act, dim_ordering=self.dim_ordering))
/u/suhubdyd/research/prednet/prednet.py:190: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(96, (3, 3), padding="same", activation=<function ..., data_format="channels_last")`
  self.conv_layers['ahat'].append(Convolution2D(self.stack_sizes[l], self.Ahat_filt_sizes[l], self.Ahat_filt_sizes[l], border_mode='same', activation=act, dim_ordering=self.dim_ordering))
/u/suhubdyd/research/prednet/prednet.py:193: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(192, (3, 3), padding="same", activation=<function ..., data_format="channels_last")`
  self.conv_layers['a'].append(Convolution2D(self.stack_sizes[l+1], self.A_filt_sizes[l], self.A_filt_sizes[l], border_mode='same', activation=self.A_activation, dim_ordering=self.dim_ordering))
/u/suhubdyd/research/prednet/prednet.py:187: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(192, (3, 3), padding="same", activation=<function ..., data_format="channels_last")`
  self.conv_layers[c].append(Convolution2D(self.R_stack_sizes[l], self.R_filt_sizes[l], self.R_filt_sizes[l], border_mode='same', activation=act, dim_ordering=self.dim_ordering))
/u/suhubdyd/research/prednet/prednet.py:190: UserWarning: Update your `Conv2D` call to the Keras 2 API: `Conv2D(192, (3, 3), padding="same", activation=<function ..., data_format="channels_last")`
  self.conv_layers['ahat'].append(Convolution2D(self.stack_sizes[l], self.Ahat_filt_sizes[l], self.Ahat_filt_sizes[l], border_mode='same', activation=act, dim_ordering=self.dim_ordering))
/u/suhubdyd/research/prednet/prednet.py:195: UserWarning: Update your `UpSampling2D` call to the Keras 2 API: `UpSampling2D(data_format="channels_last")`
  self.upsample = UpSampling2D(dim_ordering=self.dim_ordering)
/u/suhubdyd/research/prednet/prednet.py:196: UserWarning: Update your `MaxPooling2D` call to the Keras 2 API: `MaxPooling2D(data_format="channels_last")`
  self.pool = MaxPooling2D(dim_ordering=self.dim_ordering)
Traceback (most recent call last):
  File "kitti_train.py", line 59, in <module>
    errors = prednet(inputs)  # errors will be (batch_size, nt, nb_layers)
  File "/u/suhubdyd/.conda/envs/lisa/lib/python2.7/site-packages/keras/layers/recurrent.py", line 243, in __call__
    return super(Recurrent, self).__call__(inputs, **kwargs)
  File "/u/suhubdyd/.conda/envs/lisa/lib/python2.7/site-packages/keras/engine/topology.py", line 558, in __call__
    self.build(input_shapes[0])
  File "/u/suhubdyd/research/prednet/prednet.py", line 216, in build
    if self.initial_weights is not None:
AttributeError: 'PredNet' object has no attribute 'initial_weights'
xukai8 commented 7 years ago

@bill-lotter @arvoelke I got the same problem, I use the keras==2.0.6 and the tensorflow backend.

Traceback (most recent call last): File "/home/xk/PycharmProjects/prednet/kitti_train.py", line 59, in <module> errors = prednet(inputs) # errors will be (batch_size, nt, nb_layers) File "/home/xk/anaconda3/envs/tf2/lib/python2.7/site-packages/keras/layers/recurrent.py", line 262, in __call__ return super(Recurrent, self).__call__(inputs, **kwargs) File "/home/xk/anaconda3/envs/tf2/lib/python2.7/site-packages/keras/engine/topology.py", line 569, in __call__ self.build(input_shapes[0]) File "/home/xk/PycharmProjects/prednet/prednet.py", line 216, in build if self.initial_weights is not None: AttributeError: 'PredNet' object has no attribute 'initial_weights'

bill-lotter commented 7 years ago

See cc76248 for downloading weights that are compatible with Keras 2.0. You can also convert old PredNet weights for Keras 2.0 by using convert_model_to_keras2 in keras_utils.py.