public static void Pixbuf(Pixbuf Digit, ManagedCNN cnn, ref int digit, ref double[] Probability) { // Bitmap Data is transposed var Transposed = new ManagedArray(28, 28, 1); var TestDigit = new ManagedArray(28, 28, 1); var ScaledDigit = Digit.ScaleSimple(28, 28, InterpType.Hyper); Convert(ScaledDigit, TestDigit); ManagedMatrix.Transpose(Transposed, TestDigit); cnn.FeedForward(Transposed); digit = 0; double max = double.MinValue; for (int y = 0; y < cnn.Output.y; y++) { var val = cnn.Output[0, y]; Probability[y] = val; if (val > max) { max = val; digit = y; } } ScaledDigit.Dispose(); ManagedOps.Free(TestDigit, Transposed); }
public static Pixbuf Get(ManagedCNN cnn, int layer, int i, int j) { if (layer >= 0 && layer < cnn.Layers.Count && cnn.Layers[layer].Type == LayerTypes.Convolution && i >= 0 && i < cnn.Layers[layer].FeatureMap.i && j >= 0 && j < cnn.Layers[layer].FeatureMap.j) { var FeatureMap = new ManagedArray(cnn.Layers[layer].FeatureMap.x, cnn.Layers[layer].FeatureMap.y, cnn.Layers[layer].FeatureMap.z); var Transposed = new ManagedArray(FeatureMap); var pixbuf = new Pixbuf(Colorspace.Rgb, false, 8, FeatureMap.y, FeatureMap.x); ManagedOps.Copy4DIJ2D(FeatureMap, cnn.Layers[layer].FeatureMap, i, j); ManagedMatrix.Transpose(Transposed, FeatureMap); // Get normalization values double min = Double.MaxValue; double max = Double.MinValue; FullyConnected.GetNormalization(Transposed, ref min, ref max); Activation.Draw(pixbuf, Transposed, min, max); ManagedOps.Free(Transposed); return(pixbuf); } // return empty pixbuf return(new Pixbuf(Colorspace.Rgb, false, 8, 1, 1)); }
public static Pixbuf Get(ManagedCNN cnn, int layer) { if (layer >= 0 && layer < cnn.Layers.Count && cnn.Layers[layer].Type == LayerTypes.Convolution) { var Transposed = new ManagedArray(cnn.Layers[layer].Bias); ManagedMatrix.Transpose(Transposed, cnn.Layers[layer].Bias); var pixbuf = new Pixbuf(Colorspace.Rgb, false, 8, Transposed.x, Transposed.y); // Get normalization values double min = Double.MaxValue; double max = Double.MinValue; FullyConnected.GetNormalization(Transposed, ref min, ref max); Activation.Draw(pixbuf, Transposed, min, max); ManagedOps.Free(Transposed); return(pixbuf); } // return empty pixbuf return(new Pixbuf(Colorspace.Rgb, false, 8, 1, 1)); }
public static void Bitmap(Bitmap Digit, ManagedCNN cnn, ref int digit, ref double[] Probability) { // Bitmap Data is transposed var Transposed = new ManagedArray(28, 28, 1); var TestDigit = new ManagedArray(28, 28, 1); var ScaledDigit = Resize(Digit, 28, 28, true); Convert(ScaledDigit, TestDigit); ManagedMatrix.Transpose(Transposed, TestDigit); cnn.FeedForward(Transposed); digit = 0; double max = 0; for (int y = 0; y < cnn.Output.y; y++) { var val = cnn.Output[0, y]; Probability[y] = val; if (val > max) { max = val; digit = y; } } ScaledDigit.Dispose(); ManagedOps.Free(TestDigit, Transposed); }
public static Bitmap Get(ManagedCNN cnn, int layer, bool transpose = true) { if (layer >= 0 && layer < cnn.Layers.Count && cnn.Layers[layer].Type == LayerTypes.Convolution) { if (transpose) { var Transposed = new ManagedArray(cnn.Layers[layer].Bias, false); ManagedMatrix.Transpose(Transposed, cnn.Layers[layer].Bias); var bitmap = new Bitmap(Transposed.x, Transposed.y, PixelFormat.Format24bppRgb); // Get normalization values double min = Double.MaxValue; double max = Double.MinValue; GetNormalization(Transposed, ref min, ref max); Draw(bitmap, Transposed, min, max); ManagedOps.Free(Transposed); return(bitmap); } else { var bitmap = new Bitmap(cnn.Layers[layer].Bias.x, cnn.Layers[layer].Bias.y, PixelFormat.Format24bppRgb); // Get normalization values double min = Double.MaxValue; double max = Double.MinValue; GetNormalization(cnn.Layers[layer].Bias, ref min, ref max); Draw(bitmap, cnn.Layers[layer].Bias, min, max); return(bitmap); } } // return empty bitmap return(new Bitmap(1, 1, PixelFormat.Format24bppRgb)); }
public static Bitmap Get(ManagedCNN cnn, int layer, int map) { if (layer >= 0 && layer < cnn.Layers.Count && map >= 0 && map < cnn.Layers[layer].Activation.i) { var Activation = new ManagedArray(cnn.Layers[layer].Activation.x, cnn.Layers[layer].Activation.y, cnn.Layers[layer].Activation.z); var Transposed = new ManagedArray(Activation); var bitmap = new Bitmap(cnn.Layers[layer].Activation.x, cnn.Layers[layer].Activation.y, PixelFormat.Format24bppRgb); ManagedOps.Copy4D2D(Activation, cnn.Layers[layer].Activation, 0, map); ManagedMatrix.Transpose(Transposed, Activation); // Get normalization values double min = Double.MaxValue; double max = Double.MinValue; for (int y = 0; y < Transposed.y; y++) { for (int x = 0; x < Transposed.x; x++) { if (Transposed[x, y] > max) { max = Transposed[x, y]; } if (Transposed[x, y] < min) { min = Transposed[x, y]; } } } Draw(bitmap, Transposed, min, max); ManagedOps.Free(Activation, Transposed); return(bitmap); } // return empty bitmap return(new Bitmap(1, 1, PixelFormat.Format24bppRgb)); }
public static Pixbuf Get(ManagedCNN cnn, int layer, int map) { if (layer >= 0 && layer < cnn.Layers.Count && map >= 0 && map < cnn.Layers[layer].Activation.i) { var Activation = new ManagedArray(cnn.Layers[layer].Activation.x, cnn.Layers[layer].Activation.y, cnn.Layers[layer].Activation.z); var Transposed = new ManagedArray(Activation); var pixbuf = new Pixbuf(Colorspace.Rgb, false, 8, Activation.y, Activation.x); ManagedOps.Copy4D2D(Activation, cnn.Layers[layer].Activation, 0, map); ManagedMatrix.Transpose(Transposed, Activation); // Get normalization values double min = Double.MaxValue; double max = double.MinValue; for (int y = 0; y < Transposed.y; y++) { for (int x = 0; x < Transposed.x; x++) { if (Transposed[x, y] > max) { max = Transposed[x, y]; } if (Transposed[x, y] < min) { min = Transposed[x, y]; } } } Draw(pixbuf, Transposed, min, max); ManagedOps.Free(Activation, Transposed); return(pixbuf); } // return empty pixbuf return(new Pixbuf(Colorspace.Rgb, false, 8, 1, 1)); }
public static Bitmap Get(ManagedCNN cnn, int layer, int i, int j) { if (layer >= 0 && layer < cnn.Layers.Count && i >= 0 && i < cnn.Layers[layer].FeatureMap.i && j >= 0 && j < cnn.Layers[layer].FeatureMap.j) { var FeatureMap = new ManagedArray(cnn.Layers[layer].FeatureMap.x, cnn.Layers[layer].FeatureMap.y, cnn.Layers[layer].FeatureMap.z); var Transposed = new ManagedArray(FeatureMap); var bitmap = new Bitmap(cnn.Layers[layer].FeatureMap.x, cnn.Layers[layer].FeatureMap.y, PixelFormat.Format24bppRgb); ManagedOps.Copy4DIJ2D(FeatureMap, cnn.Layers[layer].FeatureMap, i, j); ManagedMatrix.Transpose(Transposed, FeatureMap); // Get normalization values double min = Double.MaxValue; double max = Double.MinValue; for (int y = 0; y < Transposed.y; y++) { for (int x = 0; x < Transposed.x; x++) { if (Transposed[x, y] > max) { max = Transposed[x, y]; } if (Transposed[x, y] < min) { min = Transposed[x, y]; } } } Draw(bitmap, Transposed, min, max); ManagedOps.Free(FeatureMap, Transposed); return(bitmap); } // return empty bitmap return(new Bitmap(1, 1, PixelFormat.Format24bppRgb)); }
void InitializeNetwork() { cnn = Utility.LoadCNN(BaseDirectory, "modelcnn"); }