How to pass the below tensor to a embedding Layer

username: KURUVILLA_ABRAHAM
cooked: <p>Target_color = torch.zeros(1,1,3, dtype=torch.float)<br>
Target_color[:,:,2] = 255<br>
Target_color = Target_color.to(DEVICE)</p>
<p>below is my model</p>
<p>class Discriminator(nn.Module):<br>
def <strong>init</strong>(self,num_classes,image_size):<br>
super(Discriminator, self).<strong>init</strong>()<br>
self.image_size = image_size</p>
<pre><code>    self.main = nn.Sequential(
        nn.Conv2d(6, 64, 4, stride=2, padding=1),
        nn.LeakyReLU(0.2, inplace=True),

        nn.Conv2d(64, 128, 4, stride=2, padding=1),
        nn.InstanceNorm2d(128),
        nn.LeakyReLU(0.2, inplace=True),

        nn.Conv2d(128, 256, 4, stride=2, padding=1),
        nn.InstanceNorm2d(256),
        nn.LeakyReLU(0.2, inplace=True),

        nn.Conv2d(256, 512, 4, padding=1),
        nn.InstanceNorm2d(512),
        nn.LeakyReLU(0.2, inplace=True),

        nn.Conv2d(512, 1, 4, padding=1),
        nn.Sigmoid()
    )
    # self.label_condition_disc = nn.Sequential(nn.Embedding(1, 3),nn.Linear(3, 3*256*256),
    #                             nn.ReLU(True))
    self.embed = nn.Embedding(num_classes,self.image_size*self.image_size)

def forward(self, inputs):
    x,label = inputs
    label_output = self.embed(label)
    label_output = label_output.view(-1,3,self.image_size,self.image_size)
    concat = torch.cat((x, label_output), dim=1)
    x = self.main(concat)
    x = F.avg_pool2d(x, x.size()[2:])
    
    x = torch.flatten(x, 1)
    return x</code></pre>

username: anantguptadbl
cooked: <pre><code class="lang-auto">embed=torch.nn.Embedding(10, 100)
embed(torch.Tensor([0,1,1,4])) # This will give you an error
embed(torch.Tensor([0,1,1,4]).type(torch.long)) # You need to convert it to int or long
</code></pre>

username: KURUVILLA_ABRAHAM
cooked: <p>Hi anant,</p>
<p>Have to use torch.tensor([255,0,0]) to the embedding layer …</p>
<p>Also how did u decide to use of embedding 10,100</p>

username: anantguptadbl
cooked: <p><a class="mention" href="/u/kuruvilla_abraham">@KURUVILLA_ABRAHAM</a> the <code>(10,100)</code> is just an example to showcase.</p>
<p>In order to pass<code> torch.tensor([255,0,0])</code> to the embedding, assign it as <code>torch.LongTensor([255, 0, 0])</code></p>

username: KURUVILLA_ABRAHAM
cooked: <p>Ok can you also tell why and what embedding size we will be using for the same tensor</p>

username: KURUVILLA_ABRAHAM
cooked: <aside class="quote no-group" data-username="anantguptadbl" data-post="2" data-topic="143487">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/anantguptadbl/48/17784_2.png" class="avatar"> anantguptadbl:</div>
<blockquote>
<p><code>embed(torch.Tensor([0,1,1,4]).type(torch.long)) </code></p>
</blockquote>
</aside>
<p>I am passing this way -</p>
<p>embed=torch.nn.Embedding(300, 3)<br>
embed(torch.Tensor([255,0,0]).type(torch.long))</p>
<p>Is this the correct way.</p>

username: anantguptadbl
cooked: <p>Yes this is the correct way <img src="https://discuss.pytorch.org/images/emoji/apple/+1.png?v=12" title=":+1:" class="emoji" alt=":+1:"></p>