public static Model CreateModel(int classCount) { var activation = tf.keras.activations.elu_fn; const int filterCount = 8; int[] resNetFilters = { filterCount, filterCount, filterCount }; return(new Sequential(new Layer[] { new Dropout(rate: 0.05), Conv2D.NewDyn(filters: filterCount, kernel_size: 5, padding: "same"), Activation.NewDyn(activation), new MaxPool2D(pool_size: 2), new ResNetBlock(kernelSize: 3, filters: resNetFilters, activation: activation), new ResNetBlock(kernelSize: 3, filters: resNetFilters, activation: activation), new ResNetBlock(kernelSize: 3, filters: resNetFilters, activation: activation), new ResNetBlock(kernelSize: 3, filters: resNetFilters, activation: activation), new MaxPool2D(), new ResNetBlock(kernelSize: 3, filters: resNetFilters, activation: activation), new ResNetBlock(kernelSize: 3, filters: resNetFilters, activation: activation), new MaxPool2D(), new ResNetBlock(kernelSize: 3, filters: resNetFilters, activation: activation), new ResNetBlock(kernelSize: 3, filters: resNetFilters, activation: activation), new AvgPool2D(pool_size: 2), new Flatten(), new Dense(units: classCount, activation: tf.nn.softmax_fn), })); }
public ResNetBlock(int kernelSize, int[] filters) { for (int part = 0; part < PartCount; part++) { this.convs.Add(this.Track(part == 1 ? Conv2D.NewDyn(filters[part], kernel_size: kernelSize, padding: "same") : Conv2D.NewDyn(filters[part], kernel_size: (1, 1)))); this.batchNorms.Add(this.Track(new BatchNormalization())); } }
public ResNetBlock(int kernelSize, int[] filters, PythonFunctionContainer?activation = null) { this.activation = activation ?? tf.keras.activations.relu_fn; for (int part = 0; part < PartCount; part++) { this.convs.Add(this.Track(part == 1 ? Conv2D.NewDyn(filters: filters[part], kernel_size: kernelSize, padding: "same") : Conv2D.NewDyn(filters[part], kernel_size: (1, 1)))); this.batchNorms.Add(this.Track(new BatchNormalization())); } this.outputChannels = filters[PartCount - 1]; }