How can I use values read from TFRecords as arguments to tf.reshape?

后端 未结 2 1867
谎友^
谎友^ 2021-01-05 00:41
def read_and_decode(filename_queue):
  reader = tf.TFRecordReader()
  _, serialized_example = reader.read(filename_queue)
  fe         


        
2条回答
  •  臣服心动
    2021-01-05 01:12

    You're very close to having a working solution! Right now there's no automatic way to give TensorFlow a list made up of tensors and numbers and make a tensor from it, which tf.reshape() is expecting. The answer is to use tf.stack(), which explicitly takes a list of N-dimensional tensors (or things convertible to tensors) and packs them into an (N+1)-dimensional tensor.

    This means you can write:

    features = ...  # Parse from an example proto.
    height = tf.cast(features['height'], tf.int32)
    width = tf.cast(features['width'], tf.int32)
    
    image = tf.reshape(image, tf.stack([height, width, 3]))
    

提交回复
热议问题