3
$\begingroup$

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

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

$\endgroup$
0

1 Answer 1

4
$\begingroup$

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.

$\endgroup$
3
  • 1
    $\begingroup$ Thanks, I've represented the 2048 to 300*100=30000 and reshaped to 100x300, and this worked $\endgroup$ Commented Jan 1, 2020 at 8:11
  • 1
    $\begingroup$ I'm glad it helped! $\endgroup$ Commented Jan 1, 2020 at 10:22
  • 1
    $\begingroup$ 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.) $\endgroup$
    – DukeZhou
    Commented Jan 2, 2020 at 22:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .