1 /** Tensorflow for D. 2 3 TODO: 4 - https://github.com/tensorflow/tensorflow/blob/master/tensorflow/cc/tutorials/example_trainer.cc 5 */ 6 module tfd; 7 8 import mir.ndslice; 9 import std.stdio; 10 // import core.stdcpp.memory : unique_ptr; 11 12 extern (C++, tensorflow) 13 struct Scope 14 { 15 static Scope NewRootScope(); 16 17 // struct Impl; 18 19 // private: 20 // unique_ptr!Impl impl_; 21 } 22 23 unittest 24 { 25 26 } 27 28 unittest 29 { 30 // writeln("graph def usage"); 31 // TODO(jeff,opensource): This should really be a more interesting 32 // computation. Maybe turn this into an mnist model instead? 33 // Scope root = Scope.NewRootScope(); 34 // import tfd.ops; 35 36 // // A = [3 2; -1 0]. Using Const<float> means the result will be a 37 // // float tensor even though the initializer has integers. 38 // auto a = Const!float(root, [[3, 2], [-1, 0]]); 39 40 // // x = [1.0; 1.0] 41 // auto x = Const(root.WithOpName("x"), [[1.0f], [1.0f]]); 42 43 // // y = A * x 44 // auto y = MatMul(root.WithOpName("y"), a, x); 45 46 // // y2 = y.^2 47 // auto y2 = Square(root, y); 48 49 // // y2_sum = sum(y2). Note that you can pass constants directly as 50 // // inputs. Sum() will automatically create a Const node to hold the 51 // // 0 value. 52 // auto y2_sum = Sum(root, y2, 0); 53 54 // // y_norm = sqrt(y2_sum) 55 // auto y_norm = Sqrt(root, y2_sum); 56 57 // // y_normalized = y ./ y_norm 58 // Div(root.WithOpName("y_normalized"), y, y_norm); 59 60 // GraphDef def; 61 // TF_CHECK_OK(root.ToGraphDef(&def)); 62 } 63 64 // unittest 65 // { 66 // writeln("example trainer"); 67 68 // struct Options { 69 // int num_concurrent_sessions = 1; // The number of concurrent sessions 70 // int num_concurrent_steps = 10; // The number of concurrent steps 71 // int num_iterations = 100; // Each step repeats this many times 72 // bool use_gpu = false; // Whether to use gpu in the training 73 // }; 74 75 // }