Esempio n. 1
0
    internal static tensor_t <float> to_tensor(List <List <List <float> > > data)
    {
        int z = data.Count;
        int y = data[0].Count;
        int x = data[0][0].Count;


        tensor_t <float> t = new tensor_t <float>(x, y, z);

        for (int i = 0; i < x; i++)
        {
            for (int j = 0; j < y; j++)
            {
                for (int k = 0; k < z; k++)
                {
                    t.functorMethod(i, j, k) = data[k][j][i];
                }
            }
        }
        return(t.functorMethod);
    }
Esempio n. 2
0
    static int Main()
    {
        vector <case_t> cases = read_test_cases();

        vector <layer_t> layers = new vector <layer_t>();

        conv_layer_t layer1 = new conv_layer_t(1, 5, 8, cases[0].data.size); // 28 * 28 * 1 -> 24 * 24 * 8
                                                                             //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
                                                                             //ORIGINAL LINE: relu_layer_t * layer2 = new relu_layer_t(layer1->out.size);
        relu_layer_t layer2 = new relu_layer_t(new point_t([email protected]));
        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: pool_layer_t * layer3 = new pool_layer_t(2, 2, layer2->out.size);
        pool_layer_t layer3 = new pool_layer_t(2, 2, new point_t([email protected])); // 24 * 24 * 8 -> 12 * 12 * 8

        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: conv_layer_t * layer4 = new conv_layer_t(1, 3, 10, layer3->out.size);
        conv_layer_t layer4 = new conv_layer_t(1, 3, 10, new point_t([email protected])); // 12 * 12 * 6 -> 10 * 10 * 10
                                                                                         //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
                                                                                         //ORIGINAL LINE: relu_layer_t * layer5 = new relu_layer_t(layer4->out.size);
        relu_layer_t layer5 = new relu_layer_t(new point_t([email protected]));
        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: pool_layer_t * layer6 = new pool_layer_t(2, 2, layer5->out.size);
        pool_layer_t layer6 = new pool_layer_t(2, 2, new point_t([email protected])); // 10 * 10 * 10 -> 5 * 5 * 10

        //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
        //ORIGINAL LINE: fc_layer_t * layer7 = new fc_layer_t(layer6->out.size, 10);
        fc_layer_t layer7 = new fc_layer_t(new point_t([email protected]), 10); // 4 * 4 * 16 -> 10

        layers.push_back((layer_t)layer1);
        layers.push_back((layer_t)layer2);
        layers.push_back((layer_t)layer3);
        layers.push_back((layer_t)layer4);
        layers.push_back((layer_t)layer5);
        layers.push_back((layer_t)layer6);
        layers.push_back((layer_t)layer7);



        float amse = 0F;
        int   ic   = 0;

        for (int ep = 0; ep < 100000;)
        {
            foreach (case_t t in cases)
            {
                float xerr = train(layers, t.data.functorMethod, [email protected]);
                amse += xerr;

                ep++;
                ic++;

                if (ep % 1000 == 0)
                {
                    Console.Write("case ");
                    Console.Write(ep);
                    Console.Write(" err=");
                    Console.Write(amse / ic);
                    Console.Write("\n");
                }

                // if ( GetAsyncKeyState( VK_F1 ) & 0x8000 )
                // {
                //     printf( "err=%.4f%\n", amse / ic  );
                //     goto end;
                // }
            }
        }
        // end:



        while (true)
        {
            uint8_t[] data = read_file("test.ppm");

            if (data != null)
            {
                //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created:
                //ORIGINAL LINE: uint8_t * usable = data;
                uint8_t[] usable = new uint8_t(data);

                while ((uint32_t)usable != 0x0A353532)
                {
                    usable++;
                }

                //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                //#pragma pack(push, 1)
                //C++ TO C# CONVERTER TODO TASK: C# does not allow declaring types within methods:
                //			struct RGB
                //			{
                //				uint8_t r, g, b;
                //			};
                //C++ TO C# CONVERTER TODO TASK: There is no equivalent to most C++ 'pragma' directives in C#:
                //#pragma pack(pop)

                RGB[] rgb = (RGB)usable;

                tensor_t <float> image = new tensor_t <float>(28, 28, 1);
                for (int i = 0; i < 28; i++)
                {
                    for (int j = 0; j < 28; j++)
                    {
                        RGB rgb_ij = rgb[i * 28 + j];
                        image.functorMethod(j, i, 0) = ((((float)rgb_ij.r + rgb_ij.g + rgb_ij.b) / (3.0f * 255.0f)));
                    }
                }

                forward(layers, image.functorMethod);
                tensor_t <float> @out = layers.back().@out;
                for (int i = 0; i < 10; i++)
                {
                    Console.Write("[{0:D}] {1:f}\n", i, @out.functorMethod(i, 0, 0) * 100.0f);
                }

                data = null;
            }

            timespec wait = new timespec();
            wait.tv_sec  = 1;
            wait.tv_nsec = 0;
            nanosleep(wait, null);
        }
        return(0);
    }