farizrahman4u / huffmax

Huffman tree based hierarchical softmax
GNU General Public License v3.0
51 stars 17 forks source link

Error running the speed comparison script #1

Open erickrf opened 8 years ago

erickrf commented 8 years ago

I tried the test_training_speed.py script and got the following errors (using tensorflow):

Build started
Building huffman tree...
100 %Huffman tree build complete
Setting weights...
Done.
Traceback (most recent call last):
  File "eval_speed.py", line 41, in <module>
    probability = Huffmax(nb_classes, verbose=True, mode=mode)([vector, target_class])
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 514, in __call__
    self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 572, in add_inbound_node
    Node.create_node(self, inbound_layers, node_indices, tensor_indices)
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 154, in create_node
    output_tensors = to_list(outbound_layer.call(input_tensors, mask=input_masks))
  File "/Users/erick/dev/autoencoder/src/huffmax.py", line 224, in call
    y = K.batch_dot(input_vector, req_W, axes=(1, 3))
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 401, in batch_dot
    out = tf.batch_matmul(x, y, adj_x=adj_x, adj_y=adj_y)
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/gen_math_ops.py", line 390, in _batch_mat_mul
    adj_y=adj_y, name=name)
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 703, in apply_op
    op_def=op_def)
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2319, in create_op
    set_shapes_for_outputs(ret)
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1711, in set_shapes_for_outputs
    shapes = shape_func(op)
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/tensorflow/python/ops/math_ops.py", line 1557, in _BatchMatMulShape
    batch_dims = a_shape[:-2].merge_with(b_shape[:-2])
  File "/Users/erick/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/tensor_shape.py", line 570, in merge_with
    (self, other))
ValueError: Shapes () and (?, 1, 17) are not compatible
geekan commented 7 years ago

Same question @farizrahman4u

stevenzhang027 commented 7 years ago

I encountered same problem here. @farizrahman4u

rbturnbull commented 5 years ago

I'm having a similar problem using the analyze_distribution.py script. Here's the error: ValueError: Dimension 1 in both shapes must be equal, but are 100 and 10. Shapes are [?,100,1] and [?,10,4]. for 'huffmax_1/MatMul' (op: 'BatchMatMul') with input shapes: [?,100,1,1,1], [?,10,4,100,1]. Here, 100 is input_dim and 10 is nb_classes. It is occurring on line 212 of the huffmax.py. That is at this point:

            req_nodes = K.gather(self.class_path_map, target_classes)
            req_W = K.gather(self.W, req_nodes)
            y = K.batch_dot(input_vector, req_W, axes=(1, 3))

There is a mix-up in the shape here with the input_dim and the nb_classes. @farizrahman4u