You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ValueError Traceback (most recent call last)
<ipython-input-7-205d82de8a49> in <module>()
25 momentum=momentum,
26 k=1)
---> 27 train_op = cdapproximator.train(crbm, vis_data=batch_vis_data, in_data=[batch_cond_data])
~/anaconda3/lib/python3.6/site-packages/xrbm/train/cdk.py in train(self, model, vis_data, in_data, global_step, var_list, name)
74
75 # Get the model's cost function for the training data and the reconstructed data (chain_end)
---> 76 cost = model.get_cost(vis_data, chain_end, in_data)
77
78 # We a regularizer is set, then add the regularization terms to the cost function
~/anaconda3/lib/python3.6/site-packages/xrbm/models/crbm.py in get_cost(self, v_sample, chain_end, in_data)
298
299 with tf.variable_scope('fe_cost'):
--> 300 cost = tf.reduce_mean(self.free_energy(v_sample, cond)
301 - self.free_energy(chain_end, cond), reduction_indices=0)
302 return cost
~/anaconda3/lib/python3.6/site-packages/xrbm/models/crbm.py in free_energy(self, v_sample, cond)
327
328 if self.vis_type == 'binary':
--> 329 v = - tf.matmul(v_sample, tf.expand_dims(vbias_n_cond,1), name='bin_visible_term')
330 elif self.vis_type == 'gaussian':
331 v = tf.reduce_sum(0.5 * tf.square(v_sample - vbias_n_cond), reduction_indices=1, name='gauss_visible_term')
...
...
ValueError: Shape must be rank 2 but is rank 3 for 'fe_cost/free_energy/bin_visible_term' (op: 'MatMul') with input shapes: [?,4], [?,1,4].
If we check xrbm.models.crbm.free_energy (shown below), we have cond.shape to be [None, num_cond], which makes the shape of vbias_n_cond = self.vbias + tf.matmul(cond, self.A) to be [None, num_vis].
When we calculate v = - tf.matmul(v_sample, tf.expand_dims(vbias_n_cond,1), name='bin_visible_term'), v_sample.shape is [None, num_vis] and the shape of tf.expand_dims(vbias_n_cond,1) is [None, 1, num_vis], which causes the ValueError: Shape must be rank 2 but is rank 3 for 'fe_cost/free_energy/bin_visible_term' (op: 'MatMul') with input shapes: [?,4], [?,1,4].
Is it because for binary visible data, I should not define the shape of batch_cond_data = tf.placeholder(tf.float32, shape=(None, num_cond), name='cond_data')? Or any other possible reasons?
def free_energy(self, v_sample, cond):
"""
Calcuates the free-energy of a given visible tensor
Parameters
----------
v_sample: tensor
the visible units tensor
cond: tensor
the condition units tensor
Returns
-------
e: float
the free energy
"""
with tf.variable_scope('free_energy'):
bottom_up = (tf.matmul(v_sample, self.W) + # visible to hidden
tf.matmul(cond, self.B) + # condition to hidden
self.hbias) # static hidden biases
vbias_n_cond = self.vbias + tf.matmul(cond, self.A)
if self.vis_type == 'binary':
v = - tf.matmul(v_sample, tf.expand_dims(vbias_n_cond,1), name='bin_visible_term')
elif self.vis_type == 'gaussian':
v = tf.reduce_sum(0.5 * tf.square(v_sample - vbias_n_cond), reduction_indices=1, name='gauss_visible_term')
Thanks,
Tian
The text was updated successfully, but these errors were encountered:
Thanks for pointing this out. It looks like it was a bug. I've updated code in 191a2f0. Can you please check it out and confirm that it solves your issue?
Hi Omid,
I followed your Tutorial 3: Training a Conditional RBM on Timeseries Data and was trying to replace the
vis_type
to'binary'
in:Then I got a dimension error:
If we check
xrbm.models.crbm.free_energy
(shown below), we havecond.shape
to be[None, num_cond]
, which makes the shape ofvbias_n_cond = self.vbias + tf.matmul(cond, self.A)
to be[None, num_vis]
.When we calculate
v = - tf.matmul(v_sample, tf.expand_dims(vbias_n_cond,1), name='bin_visible_term')
,v_sample.shape
is[None, num_vis]
and the shape oftf.expand_dims(vbias_n_cond,1)
is[None, 1, num_vis]
, which causes theValueError: Shape must be rank 2 but is rank 3 for 'fe_cost/free_energy/bin_visible_term' (op: 'MatMul') with input shapes: [?,4], [?,1,4]
.Is it because for binary visible data, I should not define the shape of
batch_cond_data = tf.placeholder(tf.float32, shape=(None, num_cond), name='cond_data')
? Or any other possible reasons?Thanks,
Tian
The text was updated successfully, but these errors were encountered: