Coder Social home page Coder Social logo

Comments (6)

jmarintur avatar jmarintur commented on June 2, 2024

Dear @intel-hm, rather than populating the init, perhaps another simple way to connect picture and code could consist in something like this:

import torch
import torch.nn as nn
import torch.nn.functional as F


class Net(nn.Module):

    def __init__(self):
        super(Net, self).__init__()
        # 1 input image channel, 6 output channels, 5x5 square convolution
        # kernel
        self.conv1 = nn.Conv2d(1, 6, 5)
        self.conv2 = nn.Conv2d(6, 16, 5)
        # an affine operation: y = Wx + b
        self.fc1 = nn.Linear(16 * 5 * 5, 120)  # 5*5 from image dimension
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)

    def forward(self, input):
        c1 = F.relu(self.conv1(input))
        # Max pooling over a (2, 2) window
        s2 = F.max_pool2d(c1, (2, 2))
        c3 = F.relu(self.conv2(s2))
        # If the size is a square, you can specify with a single number
        s4 = F.max_pool2d(c3, 2)
        # flatten all s4 dimensions except the batch dimension, before applying fc1
        s4 = torch.flatten(s4, 1)
        f5 = F.relu(self.fc1(s4)) 
        f6 = F.relu(self.fc2(f5))
        output = self.fc3(f6)
        return output

net = Net()
net

Wdyt?

from tutorials.

intel-hm avatar intel-hm commented on June 2, 2024

from tutorials.

jmarintur avatar jmarintur commented on June 2, 2024

We could include the comments you added in your suggestion to the renaming I did within the forward.

from tutorials.

intel-hm avatar intel-hm commented on June 2, 2024

from tutorials.

jmarintur avatar jmarintur commented on June 2, 2024

Hi @intel-hm, I've just created a PR, I added you as a co-author. I slightly modify the original one.

from tutorials.

intel-hm avatar intel-hm commented on June 2, 2024

from tutorials.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.