Answers.Body: <p>You can use <code>tf.reshape()</code> method (<a href="https://www.tensorflow.org/versions/r1.14/api_docs/python/tf/reshape" rel="nofollow noreferrer">tensorflow doc</a>) to reshape <code>(2048)</code> dimensional tensor to <code>(100,300)</code>. Here's one way to do this: </p>
  
  <pre><code>input1 = tf.reshape(input1, [100,300], name="reshaped_tensor")
  </code></pre>
  
  <p>If you're not using TensorFlow but using Numpy, here's an implementation:</p>
  
  <pre><code>input1 = np.array(input1)
  input1 = np.reshape(input1, (100,300))
  </code></pre>
  
  <p>Note: You might want to follow up this layer with <code>tf.nn.conv2d</code> layers to "densify" the sparse matrix/values obtained from the above step.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-01T08:11:52.090Z
Answers.Text: Thanks, I've represented the 2048 to 300*100=30000 and reshaped to 100x300, and this worked
Answers.UserDisplayName: Stephen Philip
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-01T10:22:33.803Z
Answers.Text: I'm glad it helped!
Answers.UserDisplayName: Balraj Ashwath
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-02T22:39:04.093Z
Answers.Text: 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.)*
Answers.UserDisplayName: DukeZhou
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-12-31T07:12:18.073Z
Answers.LastActivityDate: 2019-12-31T07:12:18.073Z
Answers.UserDisplayName: Balraj Ashwath
Body: <p>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.</p>
  
  <p><a href="https://i.sstatic.net/a8S6z.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/a8S6z.png" alt="something of this sort : something of this sort"></a></p>
  
  <p>I've tried </p>
  
  <ol>
  <li>2D convolution - to map from 2048 --> 100x300 (Which is not realizable)</li>
  <li>Intermediate projections :<br>
      2048 --> 100<br>
      [100x1] X [1x300] --> [100x300] (possible but complicated)</li>
  </ol>
  
  <p>I am looking for a simple and effective solution with least linear transformations. </p>
  
  <p><a href="https://i.sstatic.net/0pM8S.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0pM8S.png" alt="This is desired"></a></p>
  
Tags: <convolutional-neural-networks>
Title: How to create a fully connected(matrix) layer with vector input
UserDisplayName: Stephen Philip
ThreadText: # How to create a fully connected(matrix) layer with vector input
  
  (Asked by: username_0 on 2019-12-31)
  
  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.
  
  [![something of this sort : something of this sort](https://i.sstatic.net/a8S6z.png)](https://i.sstatic.net/a8S6z.png)
  
  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.
  
  [![This is desired](https://i.sstatic.net/0pM8S.png)](https://i.sstatic.net/0pM8S.png)
  
  **Tags:** convolutional-neural-networks
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-12-31. Score: 4 | Accepted answer
  
  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.
  
  > **Comments:**
  > **username_0**: Thanks, I've represented the 2048 to 300*100=30000 and reshaped to 100x300, and this worked  
  > **username_1**: I'm glad it helped!  
  > **username_2**: 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.)*  
  
  ---
  
  