Created
August 6, 2016 12:35
-
-
Save hughperkins/08673fb86972b41f6f57e95cb20cd338 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| On Windows 7, run as follows: | |
| rem Download mnist from http://yann.lecun.com/exdb/mnist/index.html | |
| rem decompress into c:\mnist | |
| rem rename to change the '.' to be a '-', in the filenames | |
| rem then, in a cmd: | |
| call $DEEPCLDIR\dist\bin\activate.sh | |
| deepcl_train datadir=c:\mnist numtrain=1280 numtest=1280 | |
| c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe test.cs | |
| test.exe | |
| Run as follows (tested on Ubuntu 16.04, using mono): | |
| source $DEEPCLDIR/dist/bin/activate.sh | |
| deepcl_train datadir=/norep/data/mnist/ numtrain=1280 numtest=1280 | |
| # this will create weights.dat | |
| mcs test.cs | |
| # creates test.exe | |
| mono test.exe | |
| */ | |
| using System; | |
| using System.Diagnostics; | |
| using System.IO; | |
| using System.Runtime.Serialization; | |
| using System.Runtime.Serialization.Formatters.Binary; | |
| public class HelloWorld | |
| { | |
| static public void Main () | |
| { | |
| int batchSize = 9; | |
| int planes = 1; | |
| int imageSize = 28; | |
| Process network = new Process(); | |
| network.StartInfo.RedirectStandardOutput = true; | |
| network.StartInfo.RedirectStandardInput = true; | |
| network.StartInfo.CreateNoWindow = true; | |
| network.StartInfo.UseShellExecute = false; | |
| network.StartInfo.FileName = "./deepcl_predict"; | |
| network.StartInfo.Arguments = "batchsize=" + batchSize; | |
| network.Start(); | |
| float[,,,] floats = new float[batchSize, planes, imageSize, imageSize]; | |
| Random random = new Random(); | |
| for(int n = 0; n < batchSize; n++) { | |
| for(int p = 0; p < planes; p++) { | |
| for(int h = 0; h < imageSize; h++) { | |
| for(int w = 0; w < imageSize; w++) { | |
| floats[n,p,h,w] = (float)random.NextDouble(); | |
| } | |
| } | |
| } | |
| } | |
| int[] dims = new int[3]; | |
| dims[0] = planes; | |
| dims[1] = imageSize; | |
| dims[2] = imageSize; | |
| using (Stream myOutStream = Console.OpenStandardOutput()) | |
| { | |
| for(int i = 0; i < 3; i++) { | |
| byte[] bytes = BitConverter.GetBytes(dims[i]); | |
| network.StandardInput.BaseStream.Write(bytes, 0, bytes.Length); | |
| } | |
| Console.WriteLine("sent header"); | |
| for(int it = 0; it < 10; it++) { | |
| byte[] header = new byte[3]; | |
| header[0] = (byte)'B'; | |
| header[1] = (byte)'A'; | |
| header[2] = (byte)'T'; | |
| network.StandardInput.BaseStream.Write(header, 0, 3); | |
| for(int n = 0; n < batchSize; n++) { | |
| for(int p = 0; p < planes; p++) { | |
| for(int h = 0; h < imageSize; h++) { | |
| for(int w = 0; w < imageSize; w++) { | |
| float somefloat = (float)random.NextDouble(); | |
| byte[] bytes = BitConverter.GetBytes(somefloat); | |
| if( h == 0) { | |
| bytes[0] = 10; | |
| bytes[1] = 12; | |
| bytes[2] = 13; | |
| } | |
| network.StandardInput.BaseStream.Write(bytes, 0, bytes.Length); | |
| } | |
| } | |
| } | |
| } | |
| network.StandardInput.BaseStream.Flush(); | |
| Console.WriteLine("sent batch"); | |
| //for(int i = 0; i < batchSize; i++ ) { | |
| int count = 0; | |
| while(count < batchSize) { | |
| string outstring = network.StandardOutput.ReadLine(); | |
| Console.WriteLine(outstring); | |
| if(outstring.Substring(0, 1) == "0") { | |
| count += 1; | |
| Console.WriteLine("count " + count); | |
| } | |
| } | |
| // Console.WriteLine(); | |
| //} | |
| Console.WriteLine("read batch " + it); | |
| Console.ReadLine(); | |
| } | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment