<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;


namespace ImageClassifier
{
    public partial class Form1 : Form
    {
        [DllImport("D:\\GitHub\\build\\Caffe-prefix\\src\\Caffe-build\\examples\\cpp_classification\\Debug\\classification-d.dll")]
        public static extern IntPtr ClassifyImage(String model_file, String trained_file, String mean_file, String label_file, String image_file);

        [DllImport("D:\\GitHub\\build\\Caffe-prefix\\src\\Caffe-build\\examples\\cpp_classification\\Debug\\classification-d.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int ReleaseMemory(IntPtr ptr);

        [DllImport("D:\\GitHub\\build\\Caffe-prefix\\src\\Caffe-build\\examples\\cpp_classification\\Debug\\classification-d.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int captureFromWebCam();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String dir = "F:\\20150924-184701-f9a5_epoch_3.0\\";
            //String dir = "F:\\model\\";


            String model_file = dir + "deploy.prototxt";
            String trained_file = dir + "snapshot.caffemodel";
            String mean_file = dir + "mean.binaryproto";
            String label_file = dir + "labels.txt";
            String imageDir = "F:\\Rotated\\HeadsWithRotation3600\\000\\";

            string[] files = Directory.GetFiles(imageDir);

            int counter = 0;
            List<double> standardDeviations = new List<double>();

            foreach (string image_file in files)
            {
                List<double> predictions = new List<double>();
                for (int i = 0; i < 359; i += 36)
                {
                    string fileName = image_file.Replace("\\000\\", "\\" + i.ToString("D3") + "\\");
                    IntPtr ptr = ClassifyImage(model_file, trained_file, mean_file, label_file, fileName);

                    double[] result = new double[3];
                    Marshal.Copy(ptr, result, 0, 3);
                    ReleaseMemory(ptr);

                    if (result[2] < 4)
                    {
                        double prediction = result[0] - i;
                        if (prediction < 0)
                        {
                            prediction += 360;
                        }

                        predictions.Add(prediction);

                        Console.WriteLine("Prediction: " + prediction + "   Confidence: " + result[1] + "   Standard Deviation: " + result[2]);
                        Console.WriteLine();
                        Console.WriteLine();
                    }
                }

                if (predictions.Count != 0)
                {
                    double average = predictions.Average();
                    double sumOfSquaresOfDifferences = predictions.Select(val => (val - average) * (val - average)).Sum();
                    double sd = Math.Sqrt(sumOfSquaresOfDifferences / predictions.Count);
                    if (sd < 4)<commit_msg>Added DeSkew function<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;


namespace ImageClassifier
{
    public partial class Form1 : Form
    {
        [DllImport("D:\\GitHub\\build\\Caffe-prefix\\src\\Caffe-build\\examples\\cpp_classification\\Debug\\classification-d.dll")]
        public static extern IntPtr ClassifyImage(String model_file, String trained_file, String mean_file, String label_file, String image_file);

        [DllImport("D:\\GitHub\\build\\Caffe-prefix\\src\\Caffe-build\\examples\\cpp_classification\\Debug\\classification-d.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int ReleaseMemory(IntPtr ptr);

        [DllImport("D:\\GitHub\\build\\Caffe-prefix\\src\\Caffe-build\\examples\\cpp_classification\\Debug\\classification-d.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern int captureFromWebCam();

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String dir = "F:\\20150924-184701-f9a5_epoch_3.0\\";
            //String dir = "F:\\model\\";


            String model_file = dir + "deploy.prototxt";
            String trained_file = dir + "snapshot.caffemodel";
            String mean_file = dir + "mean.binaryproto";
            String label_file = dir + "labels.txt";
            String imageDir = "F:\\Rotated\\HeadsWithRotation3600\\000\\";

            string[] files = Directory.GetFiles(imageDir);

            int counter = 0;
            List<double> standardDeviations = new List<double>();

            foreach (string image_file in files)
            {
                List<double> predictions = new List<double>();
                
                for (int i = 0; i < 359; i += 360)
                {
                    string fileName = image_file.Replace("\\000\\", "\\" + i.ToString("D3") + "\\");
                    IntPtr ptr = ClassifyImage(model_file, trained_file, mean_file, label_file, fileName);

                    double[] result = new double[3];
                    Marshal.Copy(ptr, result, 0, 3);
                    ReleaseMemory(ptr);

                    if (result[2] < 4)
                    {
                        double prediction = result[0] - i;
                        if (prediction < 0)
                        {
                            prediction += 360;
                        }

                        predictions.Add(prediction);

                        Console.WriteLine("Prediction: " + prediction + "   Confidence: " + result[1] + "   Standard Deviation: " + result[2]);
                        Console.WriteLine();
                        Console.WriteLine();
                    }
                }

                if (predictions.Count != 0)
                {
                    double average = predictions.Average();
                    double sumOfSquaresOfDifferences = predictions.Select(val => (val - average) * (val - average)).Sum();
                    double sd = Math.Sqrt(sumOfSquaresOfDifferences / predictions.Count);
                    if (sd < 4)
{'fraction_non_alphanumeric': 0.11589895988112928, 'fraction_numerical': 0.01589895988112927, 'mean_word_length': 1.758606557377049, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5615372', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1706, 'n_words': 369}