# How to create a fully connected(matrix) layer with vector input

I am trying to replace last fully connected layer of size 4096/2048 with a matrix of size 100x300 with previous fc layer output of 2048.

I've tried

1. 2D convolution - to map from 2048 --> 100x300 (Which is not realizable)
2. Intermediate projections :
2048 --> 100
[100x1] X [1x300] --> [100x300] (possible but complicated)

I am looking for a simple and effective solution with least linear transformations.

You can use tf.reshape() method (tensorflow doc) to reshape (2048) dimensional tensor to (100,300). Here's one way to do this:

input1 = tf.reshape(input1, [100,300], name="reshaped_tensor")

If you're not using TensorFlow but using Numpy, here's an implementation:

input1 = np.array(input1)
input1 = np.reshape(input1, (100,300))

Note: You might want to follow up this layer with tf.nn.conv2d layers to "densify" the sparse matrix/values obtained from the above step.

• Thanks, I've represented the 2048 to 300*100=30000 and reshaped to 100x300, and this worked Commented Jan 1, 2020 at 8:11
• I'm glad it helped! Commented Jan 1, 2020 at 10:22
• Thanks for contributing! (The original question has been flagged as unclear--clearly it wasn't for you, so please feel free to edit the question to ensure it doesn't get closed by the community.) Commented Jan 2, 2020 at 22:39