naturomics / CapsLayer

CapsLayer: An advanced library for capsule theory
Apache License 2.0
362 stars 117 forks source link

Error "Expected binary or unicode string, got None" While trying to predict model output #11

Closed vksbhandary closed 6 years ago

vksbhandary commented 6 years ago

I am trying to use capslayer in Tensorflow (1.4.0) estimator API. Everything works well when I train the model. But for prediction it doesn't work. I have copied most of the code from vectorCapsNet.py file and commented all image reconstruction related code. My model definition looks like this:

def baseline(x, params, is_training):
  x = layers.batch_norm(x, is_training=is_training)
  conv1 = tf.contrib.layers.conv2d(x,
                                 num_outputs=256,
                                 kernel_size=9,
                                 stride=1, padding='VALID')
  primaryCaps, activation = capslayer.layers.primaryCaps(conv1,
                                                       filters=32,
                                                       kernel_size=9,
                                                       strides=2,
                                                       out_caps_shape=[8, 1])

  primaryCaps = tf.reshape(primaryCaps, shape=[params.batch_size, -1, 8, 1])

  digitCaps, activation = capslayer.layers.fully_connected(primaryCaps, 
                                                         activation, 
                                                         num_outputs=params.num_classes, 
                                                         out_caps_shape=[16, 1], 
                                                         routing_method='DynamicRouting')

  return digitCaps, activation

Error Description: TypeError: Expected binary or unicode string, got None During handling of the above exception, another exception occurred: TypeError: Failed to convert object of type <class 'list'> to Tensor. Contents: [None, 6, 6, 32, 8, 1]. Consider casting elements to a supported type. (For second error it points to this line )

I am new to Tensorflow. But it seems I am getting [None, 6, 6] shaped output from conv1 layer defined in baseline function. If its supposed to be like that maybe we want to use this method for reshaping tensor?