Input to reshape is a tensor with 37632 values, but the requested shape has 150528

前端 未结 3 1706
礼貌的吻别
礼貌的吻别 2020-12-18 03:20

I have the same question:Input to reshape is a tensor with 37632 values, but the requested shape has 150528.

 writer = tf.python_io.TFRecordWriter(\"/home/he         


        
相关标签:
3条回答
  • 2020-12-18 03:57

    I had the same error just like you, and I found the reason behind it. It is because when you store your image with .tostring(), the data is stored with the format of tf.float32. Then you decode the tfrecord with decode_raw(tf.uint8), which causes the dismatch error. I solved it by change the code to:

    image=tf.decode_raw(image_raw,tf.float32)
    

    or:

    image=tf.image.decode_jpeg(image_raw,channels=3)
    

    if you image_raw is jpeg format originally

    0 讨论(0)
  • 2020-12-18 03:58

    The problem is basically related to shape of Architecture of CNN.Let say I defined architecture shown in picture int coding we defined weights and biases in following way If we see (weights) Lets start with

    wc1 in this layer I defined 32 filters of 3x3 size will be applied

    wc2 in this layer I defined 64 filters of 3x3 size will be applied

    wc3 in this layer I defined 128 filters of 3x3 size will be applied

    wd1 38*38*128 is interesting (Where it comes from).

    And in Architecture we also defined maxpooling concept. See Architecture pic in every step 1.Lets Explain it Let say your input image is 300 x 300 x 1 (in picture it is 28x28x1) 2. (If strides defined is set to 1)Each filter will have an 300x300x1 picture so After applying 32 filter of 3x3 the we will have 32 pictures of 300x300 thus collected images will be 300x300x32

    3.After Maxpooling if (Strides=2 depends what you defined usually it is 2) image size will change from 300 x 300 x 32 to 150 x 150 x 32

    1. (If strides defined is set to 1)Now Each filter will have an 150x150x32 picture so After applying 64 filter of 3x3 the we will have 64 pictures of 300x300 thus collected images will be 150x150x(32x64)

    5.After Maxpooling if (Strides=2 depends what you defined usually it is 2) image size will change from 150x150x(32x64) to 75 x 75 x (32x64)

    1. (If strides defined is set to 1)Now Each filter will have an 75 x 75 x (32x64) picture so After applying 64 filter of 3x3 the we will have 128 pictures of 75 x 75 x (32x64) thus collected images will be 75 x 75 x (32x64x128)

    7.After Maxpooling since dimension of image is 75x75(odd dimension make it even) so it is needed to pad first (if padding defined ='Same') then it will change to 76x76(even) ** if (Strides=2 depends what you defined usually it is 2) image size will change from 76x76x(32x64x128) to **38 x 38 x (32x64x128)

    Now See 'wd1' in coding picture here comes 38*38*128

    0 讨论(0)
  • 2020-12-18 04:06

    I had the same error , so changed my code from this:

    image = tf.decode_raw(image_raw, tf.float32)
    image = tf.reshape(image, [img_width, img_height, 3])
    

    to this:

    image = tf.decode_raw(image_raw, tf.uint8)
    image = tf.reshape(image, [img_width, img_height, 3])
    
    
    # The type is now uint8 but we need it to be float.
    image = tf.cast(image, tf.float32)
    

    It is because somehow there's a mismatch in my generate_tf_record data format. I serialized it to string instead of bytelist. I notice the difference you and me, you change your image to byte . Here's how I write my image to tfrecord.

                file_path, label = sample
                image = Image.open(file_path)
                image = image.resize((224, 224))
                image_raw = np.array(image).tostring()
    
                features = {
                    'label': _int64_feature(class_map[label]),
                    'text_label': _bytes_feature(bytes(label, encoding = 'utf-8')),
                    'image': _bytes_feature(image_raw)
                }
    
                example = tf.train.Example(features=tf.train.Features(feature=features))
                writer.write(example.SerializeToString())  
    

    hope it will help.

    0 讨论(0)
提交回复
热议问题