Fashion MNIST - ANN

flora1: <p>Hi,</p>
<p>For a university project, we have to create a certain accuracy level for the famous Fashion MNIST with model of neural network.</p>
<p>I am having some issues to somehow connect the test version to the train version. I am trying to save a the best version to then load it again to evaluate:</p>
<p>I am trying to do this code but I can’t get it right.</p>
<p>model = FashionMNISTNet(*images, **labels)<br>
model.load_state_dict(torch.load(os.path.join))<br>
model.eval()<br>
TypeError                                 Traceback (most recent call last)<br>
 in ()<br>
----&gt; 1 model = FashionMNISTNet(*images, **labels)<br>
2 model.load_state_dict(torch.load(os.path.join))<br>
3 model.eval()</p>
<p>TypeError: type object argument after ** must be a mapping, not Tensor</p>

eqy: <p>Is <code>FashionMNISTNet</code> a subclass of <code>torch.nn.Module</code>? If so it is a bit strange to pass images and labels to the <code>__init__</code> function as usually the model definition itself doesn’t need to know anything about the data.</p>
<p>Can you show what the definition of <code>FashionMNISTNet</code> looks like?<br>
The <a href="https://github.com/pytorch/examples/blob/01539f9eada34aef67ae7b3d674f30634c35f468/imagenet/main.py#L192" rel="noopener nofollow ugc">Imagenet Example</a> also gives an example of how to use the model loading functions.</p>

flora1: <p>Sure, thank you for answer.</p>
<p>This is where I took the FashionMNISTNet</p>
<h1>
<a name="implement-the-mnistnet-network-architecture-1" class="anchor" href="#implement-the-mnistnet-network-architecture-1"></a>implement the MNISTNet network architecture</h1>
<p>class FashionMNISTNet(nn.Module):</p>
<pre><code># define the class constructor

def __init__(self):

    

    # call super class constructor

    super(FashionMNISTNet, self).__init__()

    

    # specify fully-connected (fc) layer 1 - in 28*28, out 100

    self.linear1 = nn.Linear(28*28, 100, bias=True) # the linearity W*x+b

    self.relu1 = nn.ReLU(inplace=True) # the non-linearity 

    self.linear2 = nn.Linear(100, 75, bias=True)

    self.relu2 = nn.ReLU(inplace=True)

    

    # specify fc layer 2 - in 75, out 50

    self.linear3 = nn.Linear(75, 50, bias=True) # the linearity W*x+b

    self.relu3 = nn.ReLU(inplace=True) # the non-linarity

    

    # specify fc layer 3 - in 50, out 10

    self.linear4 = nn.Linear(50, 10) # the linearity W*x+b

    

    # add a softmax to the last layer

    self.softmax = nn.Softmax(dim=1) # the softmax

    

# define network forward pass

def forward(self, images):

    

    # reshape image pixels

    x = images.view(-1, 28*28)

    

    # define fc layer 1 forward pass

    x = self.relu1(self.linear1(x))

    

    # define fc layer 2 forward pass

    x = self.relu2(self.linear2(x))

    # define fc layer 3 forward pass

    x = self.relu3(self.linear3(x))

    # define layer 3 forward pass

    x = self.softmax(self.linear4(x))

    

    # return forward pass result

    return x</code></pre>

eqy: <p>It seems like you shouldn’t need to pass images or labels to the constructor; you can just call <code>FashionMNISTNet</code> with any arguments (e.g., <code>model = FashionMNISTNet()</code>).</p>