简体   繁体   English

如何将4D张量流重塑为2D

[英]how to reshape a 4D tensorflow to a 2D

I have an X_train image as: 我有一个X_train图像:

X-train (37248, 32, 32, 3)

y_train (37248, 43) y_train(37248,43)

I have a feed-dictionary as 我有一个feed-dictionary as

train_feed_dict = {features: X_train, labels: train_labels}
with tf.Session() as session:
    session.run(init)
    session.run(loss, feed_dict=train_feed_dict)

My features is: 我的特点是:

features = tf.placeholder(tf.float32, shape=[None, 32, 32, 3]) 
features = tf.reshape(features, [-1, 3072])

But when I run the code I get this error, reshaping does not seem to take place. 但是,当我运行代码时,我得到了这个错误,重塑似乎没有发生。

ValueError: Cannot feed value of shape (37248, 32, 32, 3) for Tensor 'Reshape_5:0', which has shape '(?, 3072)'

I believe the error was two prong: 我相信错误是两个方面:

I had to split the data into np.array() format and flat_features = tf.reshape(features, [-1, 3072]) 我不得不将数据拆分为np.array()格式和flat_features = tf.reshape(features,[ - 1,3072])

having features=tf.reshape(features, [-1, 3072]), I had two problems so just changing the name t flat_features by itself did not work 有功能= tf.reshape(功能,[-1,3072]),我有两个问题所以只更改名称t flat_features本身不起作用

so @drpng was also right in his comment 所以@drpng在他的评论中也是对的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM