void create_network() { Console.WriteLine("Compute Device: " + computeDevice.AsString()); imageVariable = Util.inputVariable(new int[] { 28, 28, 1 }, "image_tensor"); categoricalVariable = Util.inputVariable(new int[] { 10 }, "label_tensor"); network = imageVariable; network = Layers.Convolution2D(network, 32, new int[] { 3, 3 }, computeDevice, CC.ReLU); network = CC.Pooling(network, C.PoolingType.Max, new int[] { 2, 2 }, new int[] { 2 }); network = Layers.Convolution2D(network, 64, new int[] { 3, 3 }, computeDevice, CC.ReLU); network = CC.Pooling(network, C.PoolingType.Max, new int[] { 2, 2 }, new int[] { 2 }); network = Layers.Convolution2D(network, 64, new int[] { 3, 3 }, computeDevice, CC.ReLU); network = Layers.Dense(network, 64, computeDevice, activation: CC.ReLU); network = Layers.Dense(network, 10, computeDevice); Logging.detailed_summary(network); Logging.log_number_of_parameters(network); loss_function = CC.CrossEntropyWithSoftmax(network, categoricalVariable); eval_function = CC.ClassificationError(network, categoricalVariable); learner = CC.AdamLearner( new C.ParameterVector(network.Parameters().ToArray()), new C.TrainingParameterScheduleDouble(0.001 * batch_size, (uint)batch_size), new C.TrainingParameterScheduleDouble(0.9), true, new C.TrainingParameterScheduleDouble(0.99)); trainer = CC.CreateTrainer(network, loss_function, eval_function, new C.LearnerVector(new C.Learner[] { learner })); evaluator = CC.CreateEvaluator(eval_function); }
private static OneArgumentModule Pooling(PoolingType poolingType, int kernelSize, int rank = 1, int stride = 1, bool padding = false, bool ceilMode = false, string name = "") { int[] kernelShape = new int[rank]; int[] strides = new int[rank]; bool[] autoPadding = new bool[rank]; for (int i = 0; i < rank; i++) { kernelShape[i] = kernelSize; strides[i] = stride; autoPadding[i] = padding; } return(x => C.Pooling(x, poolingType, kernelShape, strides, new BoolVector(autoPadding), ceilMode, padding, name)); }
private static OneArgumentModule Pooling(PoolingType poolingType, int [] kernelShape, int [] strides, bool [] paddings, bool ceilMode = false, string name = "") { return(x => C.Pooling(x, poolingType, kernelShape, strides, new BoolVector(paddings), ceilMode, true, name)); }