Beispiel #1
0
            public Model(int numClasses)
            {
                features = Sequential(
                    Conv2D(3, 64, kernelSize: 3, stride: 2, padding: 1),
                    Relu(inPlace: true),
                    MaxPool2D(kernelSize: new long[] { 2 }),
                    Conv2D(64, 192, kernelSize: 3, padding: 1),
                    Relu(inPlace: true),
                    MaxPool2D(kernelSize: new long[] { 2 }),
                    Conv2D(192, 384, kernelSize: 3, padding: 1),
                    Relu(inPlace: true),
                    Conv2D(384, 256, kernelSize: 3, padding: 1),
                    Relu(inPlace: true),
                    Conv2D(256, 256, kernelSize: 3, padding: 1),
                    Relu(inPlace: true),
                    MaxPool2D(kernelSize: new long[] { 2 }));

                avgPool = AdaptiveAvgPool2D(2, 2);

                classifier = Sequential(
                    Dropout(IsTraining()),
                    Linear(256 * 2 * 2, 4096),
                    Relu(inPlace: true),
                    Dropout(IsTraining()),
                    Linear(4096, 4096),
                    Relu(inPlace: true),
                    Linear(4096, numClasses)
                    );

                RegisterModule(features);
                RegisterModule(classifier);
            }
Beispiel #2
0
 private static void Train(
     NN.Module model,
     NN.Optimizer optimizer,
     Loss loss,
     IEnumerable <(TorchTensor, TorchTensor)> dataLoader,