how to shape tensor from fully connected to to 4-D

Farshid Rayhan

I am new at using tensorflow . I was trying to add CNN inside auto-encoder. I was using the example code from tflearn. My initial code was

X, Y, testX, testY = mnist.load_data(one_hot=True)
# Building the encoder
encoder = tflearn.input_data(shape=[None, 28* 28*1], name='input')
encoder = tflearn.fully_connected(encoder, 256)

# Building the decoder
decoder = tflearn.fully_connected(encoder, 256)
decoder = tflearn.fully_connected(decoder, 784, activation='sigmoid')

# Regression, with mean square error
net = tflearn.regression(decoder, optimizer='adam', learning_rate=0.001,
                         loss='mean_square', metric=None)
# Training the auto encoder
model = tflearn.DNN(net, tensorboard_verbose=0)
model.fit(X, X, n_epoch=20, validation_set=(testX, testX),
          run_id="auto_encoder", batch_size=256)

Now i added the CNN code before building the decoder like this .

encoder = tflearn.input_data(shape=[None, 28* 28*1], name='input')
encoder = tflearn.fully_connected(encoder, 256)

# my modification
network = conv_3d(encoder, 32, 3, activation='relu', regularizer="L2")

# Building the decoder
decoder = tflearn.fully_connected(network, 256)
decoder = tflearn.fully_connected(decoder, 784, activation='sigmoid')

But i get the the following error

    network = conv_2d(encoder, 32, 3, activation='relu', regularizer="L2")
  File "/usr/local/lib/python3.5/dist-packages/tflearn/layers/conv.py", line 66, in conv_2d
    assert len(input_shape) == 4, "Incoming Tensor shape must be 4-D"
AssertionError: Incoming Tensor shape must be 4-D

Now how do i convert this encoder variable to 4D Tensor ? Or is there any other way to solve the problem ?

Farshid Rayhan

SO that answer was a simple typo correction.

encoder = tflearn.input_data(shape=[None, 28* 28*1], name='input')
encoder = tflearn.fully_connected(encoder, 256)

# Correction here 3d to 2d 
network = conv_2d(encoder, 32, 3, activation='relu', regularizer="L2")

# Building the decoder
decoder = tflearn.fully_connected(network, 256)
decoder = tflearn.fully_connected(decoder, 784, activation='sigmoid')

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Slim.fully_connected:Tensor.shapeを使用して `num_outputs`を指定します

分類Dev

In Tensorflow How can I add a Tensor to another Tensor with different shape?

分類Dev

How does a (2 or 3) dimensional Fully connected layer work?

分類Dev

How to explicitly broadcast a tensor to match another's shape in tensorflow?

分類Dev

How to apply mask to a tensor and keep its original shape

分類Dev

How to get input tensor shape of an unknown PyTorch model

分類Dev

What is the shape of an image tensor in TensorFlow

分類Dev

How to scale a shape from its center as origin?

分類Dev

How can I fully reallocate a 2D array in C?

分類Dev

Numpy.Append(): ValueError: could not broadcast input array from shape (4) into shape (3)

分類Dev

TensorFlow:AttributeError: 'Tensor' object has no attribute 'shape'

分類Dev

TensorFlow 2.0 Layer with None type shape Tensor

分類Dev

How to use keras embedding layer with 3D tensor input?

分類Dev

How to get value from a theano tensor variable backed by a shared variable?

分類Dev

Connected vertices from polygon, how to get the new polygons

分類Dev

Trying to create a fully connected neural network for CIFAR-10

分類Dev

Tensorflow 2のtf.contrib.layers.fully_connected()?

分類Dev

How to achieve disc shape in D3 force simulation?

分類Dev

"ValueError: The shape of the input to "Flatten" is not fully defined" with variable length LSTM

分類Dev

/ image / Tensor Tensor( "activation_5 / Softmax:0"、shape =(?, 4)、dtype = float32)のValueErrorは、このグラフの要素ではありません

分類Dev

How to get touched shape (arc) from Android canvas?

分類Dev

how to split a pandas dataframe from wide to tall shape

分類Dev

How to construct a tree of particular shape with elements from a list

分類Dev

Extract tensor from string

分類Dev

Creating tensorflow::Tensor from Eigen::Tensor

分類Dev

Tensor Flow 2.0、kerasのConv2Dレイヤーでinput_shapeを指定する方法

分類Dev

How can i make OpenCV work fully on Raspberry Pi 4 (Raspbian Buster)?

分類Dev

tf.Tensor.set_shape()の説明

分類Dev

tf.Tensor.set_shape()の説明

Related 関連記事

  1. 1

    Slim.fully_connected:Tensor.shapeを使用して `num_outputs`を指定します

  2. 2

    In Tensorflow How can I add a Tensor to another Tensor with different shape?

  3. 3

    How does a (2 or 3) dimensional Fully connected layer work?

  4. 4

    How to explicitly broadcast a tensor to match another's shape in tensorflow?

  5. 5

    How to apply mask to a tensor and keep its original shape

  6. 6

    How to get input tensor shape of an unknown PyTorch model

  7. 7

    What is the shape of an image tensor in TensorFlow

  8. 8

    How to scale a shape from its center as origin?

  9. 9

    How can I fully reallocate a 2D array in C?

  10. 10

    Numpy.Append(): ValueError: could not broadcast input array from shape (4) into shape (3)

  11. 11

    TensorFlow:AttributeError: 'Tensor' object has no attribute 'shape'

  12. 12

    TensorFlow 2.0 Layer with None type shape Tensor

  13. 13

    How to use keras embedding layer with 3D tensor input?

  14. 14

    How to get value from a theano tensor variable backed by a shared variable?

  15. 15

    Connected vertices from polygon, how to get the new polygons

  16. 16

    Trying to create a fully connected neural network for CIFAR-10

  17. 17

    Tensorflow 2のtf.contrib.layers.fully_connected()?

  18. 18

    How to achieve disc shape in D3 force simulation?

  19. 19

    "ValueError: The shape of the input to "Flatten" is not fully defined" with variable length LSTM

  20. 20

    / image / Tensor Tensor( "activation_5 / Softmax:0"、shape =(?, 4)、dtype = float32)のValueErrorは、このグラフの要素ではありません

  21. 21

    How to get touched shape (arc) from Android canvas?

  22. 22

    how to split a pandas dataframe from wide to tall shape

  23. 23

    How to construct a tree of particular shape with elements from a list

  24. 24

    Extract tensor from string

  25. 25

    Creating tensorflow::Tensor from Eigen::Tensor

  26. 26

    Tensor Flow 2.0、kerasのConv2Dレイヤーでinput_shapeを指定する方法

  27. 27

    How can i make OpenCV work fully on Raspberry Pi 4 (Raspbian Buster)?

  28. 28

    tf.Tensor.set_shape()の説明

  29. 29

    tf.Tensor.set_shape()の説明

ホットタグ

アーカイブ