這裏我們使用全連接神經網絡(MLP) 實現的 MNIST 數字識別代碼,結構更簡單,僅包含幾個線性層和激活函數。
簡易代碼
模型定義代碼,model.py
import torch.nn as nn
# 定義一個簡單的 CNN 模型
class SimpleModel(nn.Module):
def __init__(self):
super(SimpleModel, s
一個計數器
對於普通的變量,在涉及多線程操作時,會遇到經典的線程安全問題。考慮如下代碼:
private static final int TEST_THREAD_COUNT = 100;
private static int counter = 0;
public static void main(String[] args) {
final CountDownLatch latch