mbinkowski / nntimeseries

208 stars 66 forks source link

Reshape cannot infer the missing input size for an empty tensor #2

Open petteriTeikari opened 7 years ago

petteriTeikari commented 7 years ago

There was a typo also on line 159 of SOCNN.py when trying the shared_final_weights option

out = TimeDistributed(Dense(output_length ...

that I changed to

out = TimeDistributed(Dense(self.output_length ...

And got the training started with:

I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)
Total model parameters: 7196
---current learning rate: 0.00100000
Epoch 1/1000

But then the following error happend then:

Caused by op 'softmax/Reshape_1', defined at:
  File "nntimeseries/nnts/models/SOCNN.py", line 189, in <module>
    runner.run(SOCNNmodel, log=log, limit=6)
  File "nntimeseries/nnts/utils.py", line 150, in run
    model = model_class(data, params, os.path.join(WDIR, 'tensorboard'))
  File "nntimeseries/nnts/utils.py", line 263, in __init__
    self.nn, self.io_func, self.callbacks = self.build()
  File "nntimeseries/nnts/models/SOCNN.py", line 152, in build
    sig = TimeDistributed(Activation('softmax'), name='softmax')(sig)
  File "anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 578, in __call__
    output = self.call(inputs, **kwargs)
  File "anaconda3/lib/python3.6/site-packages/keras/layers/wrappers.py", line 180, in call
    y = K.reshape(y, (-1, input_length) + output_shape[2:])
  File "anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 1568, in reshape
    return tf.reshape(x, shape)
  File "anaconda3/lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2630, in reshape
    name=name)
  File "anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
    op_def=op_def)
  File "anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2327, in create_op
    original_op=self._default_original_op, op_def=op_def)
  File "anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1226, in __init__
    self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): Reshape cannot infer the missing input size for an empty tensor unless all specified input sizes are non-zero
     [[Node: softmax/Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/gpu:0"](softmax/Softmax, softmax/Reshape_1/shape)]]
     [[Node: add/_445 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_10390_add", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]]

I guess I have to explicitly set shape for the sig of sig = TimeDistributed(Activation('softmax'), name='softmax')(sig) ?

mbinkowski commented 7 years ago

Hi @petteriTeikari, thanks for letting me know about the problem.

There was a bug in nnts.household.HouseholdGenerator that assigned wrong (zero) output dimension for the network, probably that's why Reshape could not infer the missing input size for an empty tensor. Should work well now.

Please also make sure you have up-to-date keras version (I run it successfully with 2.0.2 and 2.0.3).

Apologies for late reply.

ahmad53135 commented 6 years ago

I had this problem and for me, it was due to facing a null matrix during my computation so I just add a tf.cond for empty matrix