<jupyter_start><jupyter_text>Define model<jupyter_code>class LeNet(nn.Module):
    def __init__(self):
        super(LeNet, self).__init__()
        self.conv1 = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=5)
        self.conv2 = nn.Conv2d(in_channels=6, out_channels=16, kernel_size=5)
        self.fc1 = nn.Linear(in_features=5*5*16, out_features=120)
        self.fc2 = nn.Linear(in_features=120, out_features=84)
        self.fc3 = nn.Linear(in_features=84, out_features=10)
        self.pool = nn.MaxPool2d(kernel_size=2, stride=2)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        x = self.pool(x)
        x = F.relu(self.conv2(x))
        x = self.pool(x)
        x = x.view(-1, 16*5*5)
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x
        
net = LeNet()
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(net.parameters(),lr=0.001, momentum=0.9)
for epoch in range(3):
    print("epoch:",epoch)
    lossOfNet = 0.0
    for i,data in enumerate(trainLoader):
        inputs, labels = data
        optimizer.zero_grad()
        output = net(inputs)
        loss = criterion(output, labels)
        loss.backward()
        optimizer.step()
        lossOfNet+=loss.item()
        if i%100==99:
            print("ecoch %d, batch %5d, loss: %.3f"%(epoch, i+1, lossOfNet))
            lossOfNet=0.0
print("Train done!")
# dataiter = iter(testLoader) who it can not work?
dataiter = iter(trainLoader)
correct=0
total=0<jupyter_output><empty_output><jupyter_text>Predict<jupyter_code>with torch.no_grad():
    for data in dataiter:
        images, labels = data
        output = net(images)
        _, predicted = torch.max(output.data, 1)
        total += labels.size(0)
        correct += (predicted==labels).sum().item()
print("accuracy:",correct/total)<jupyter_output>accuracy: 0.4394
{'fraction_non_alphanumeric': 0.14574468085106382, 'fraction_numerical': 0.03776595744680851, 'mean_word_length': 2.8466257668711656, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '548233', 'license': 'MIT', 'n_tokens_mistral': 716, 'n_tokens_neox': 689, 'n_words': 122, 'path': 'vision/torchvisionDemo.ipynb', 'repo_name': 'zhicaihuang/AI_workshop', 'size': '1880'}