| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8dfc3b7 commit 649623b
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -193,7 +193,9 @@ public Operation _apply_op_helper(string op_type_name, string name = "", dynamic | |||
| 193 | 193 | } | |
| 194 | 194 | ||
| 195 | 195 | // Add Op to graph | |
| 196 | - var op = g.create_op(op_type_name, inputs.ToArray(), output_types.ToArray(), | ||
| 196 | + var op = g.create_op(op_type_name, | ||
| 197 | + inputs.ToArray(), | ||
| 198 | + output_types.ToArray(), | ||
| 197 | 199 | name: scope, | |
| 198 | 200 | input_types: input_types.ToArray(), | |
| 199 | 201 | attrs: attr_protos, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,7 +61,7 @@ public virtual SaverDef _build_internal(RefVariable[] names_to_saveables, | |||
| 61 | 61 | bool sharded = false, | |
| 62 | 62 | int max_to_keep = 5, | |
| 63 | 63 | float keep_checkpoint_every_n_hours = 10000, | |
| 64 | - string name = "", | ||
| 64 | + string name = null, | ||
| 65 | 65 | bool restore_sequentially = false, | |
| 66 | 66 | string filename = "model", | |
| 67 | 67 | bool build_save = true, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,7 @@ public Saver(RefVariable[] var_list = null, | |||
| 37 | 37 | bool sharded = false, | |
| 38 | 38 | int max_to_keep = 5, | |
| 39 | 39 | float keep_checkpoint_every_n_hours = 10000, | |
| 40 | - string name = "", | ||
| 40 | + string name = null, | ||
| 41 | 41 | bool restore_sequentially = false, | |
| 42 | 42 | SaverDef saver_def = null, | |
| 43 | 43 | ISaverBuilder builder = null, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,10 +27,7 @@ public name_scope(string name, string default_name = "", object values = null) | |||
| 27 | 27 | ||
| 28 | 28 | public void __enter__() | |
| 29 | 29 | { | |
| 30 | - if (String.IsNullOrEmpty(_name)) | ||
| 31 | - { | ||
| 32 | - _name = _default_name; | ||
| 33 | - } | ||
| 30 | + _name = _name == null ? _default_name : _name; | ||
| 34 | 31 | ||
| 35 | 32 | Graph g = null; | |
| 36 | 33 | if (_values is List<Tensor> values) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,7 +57,7 @@ public void Run() | |||
| 57 | 57 | var grad = tf.train.GradientDescentOptimizer(learning_rate); | |
| 58 | 58 | var optimizer = grad.minimize(cost);*/ | |
| 59 | 59 | ||
| 60 | - var new_saver = tf.train.import_meta_graph("save_model.meta", import_scope: "import"); | ||
| 60 | + var new_saver = tf.train.import_meta_graph("linear_regression.meta"); | ||
| 61 | 61 | ||
| 62 | 62 | var X = graph.OperationByName("Placeholder"); | |
| 63 | 63 | var Y = graph.OperationByName("Placeholder_1"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ | |||
| 14 | 14 | # Parameters | |
| 15 | 15 | learning_rate = 0.01 | |
| 16 | 16 | training_epochs = 1000 | |
| 17 | - display_step = 50 | ||
| 17 | + display_step = 10 | ||
| 18 | 18 | ||
| 19 | 19 | # Training Data | |
| 20 | 20 | train_X = numpy.asarray([3.3,4.4,5.5,6.71,6.93,4.168,9.779,6.182,7.59,2.167, | |
@@ -23,28 +23,41 @@ | |||
| 23 | 23 | 2.827,3.465,1.65,2.904,2.42,2.94,1.3]) | |
| 24 | 24 | n_samples = train_X.shape[0] | |
| 25 | 25 | ||
| 26 | - # tf Graph Input | ||
| 27 | - X = tf.placeholder("float") | ||
| 28 | - Y = tf.placeholder("float") | ||
| 29 | - | ||
| 30 | - # Set model weights | ||
| 31 | - W = tf.Variable(rng.randn(), name="weight") | ||
| 32 | - b = tf.Variable(rng.randn(), name="bias") | ||
| 33 | - | ||
| 34 | - # Construct a linear model | ||
| 35 | - mul = tf.multiply(X, W) | ||
| 36 | - pred = tf.add(mul, b) | ||
| 37 | - | ||
| 38 | - # Mean squared error | ||
| 39 | - sub = pred-Y | ||
| 40 | - pow = tf.pow(sub, 2) | ||
| 41 | - | ||
| 42 | - reduce = tf.reduce_sum(pow) | ||
| 43 | - cost = reduce/(2*n_samples) | ||
| 44 | - # Gradient descent | ||
| 45 | - # Note, minimize() knows to modify W and b because Variable objects are trainable=True by default | ||
| 46 | - grad = tf.train.GradientDescentOptimizer(learning_rate) | ||
| 47 | - optimizer = grad.minimize(cost) | ||
| 26 | + if False: | ||
| 27 | + # tf Graph Input | ||
| 28 | + X = tf.placeholder("float") | ||
| 29 | + Y = tf.placeholder("float") | ||
| 30 | + | ||
| 31 | + # Set model weights | ||
| 32 | + W = tf.Variable(-0.06, name="weight") | ||
| 33 | + b = tf.Variable(-0.73, name="bias") | ||
| 34 | + | ||
| 35 | + # Construct a linear model | ||
| 36 | + mul = tf.multiply(X, W) | ||
| 37 | + pred = tf.add(mul, b) | ||
| 38 | + | ||
| 39 | + # Mean squared error | ||
| 40 | + sub = pred-Y | ||
| 41 | + pow = tf.pow(sub, 2) | ||
| 42 | + | ||
| 43 | + reduce = tf.reduce_sum(pow) | ||
| 44 | + cost = reduce/(2*n_samples) | ||
| 45 | + # Gradient descent | ||
| 46 | + # Note, minimize() knows to modify W and b because Variable objects are trainable=True by default | ||
| 47 | + grad = tf.train.GradientDescentOptimizer(learning_rate) | ||
| 48 | + optimizer = grad.minimize(cost) | ||
| 49 | + # tf.train.export_meta_graph(filename='save_model.meta'); | ||
| 50 | + else: | ||
| 51 | + # tf Graph Input | ||
| 52 | + new_saver = tf.train.import_meta_graph("save_model.meta") | ||
| 53 | + nodes = tf.get_default_graph()._nodes_by_name; | ||
| 54 | + optimizer = nodes["GradientDescent"] | ||
| 55 | + cost = nodes["truediv"].outputs[0] | ||
| 56 | + X = nodes["Placeholder"].outputs[0] | ||
| 57 | + Y = nodes["Placeholder_1"].outputs[0] | ||
| 58 | + W = nodes["weight"].outputs[0] | ||
| 59 | + b = nodes["bias"].outputs[0] | ||
| 60 | + pred = nodes["Add"].outputs[0] | ||
| 48 | 61 | ||
| 49 | 62 | # Initialize the variables (i.e. assign their default value) | |
| 50 | 63 | init = tf.global_variables_initializer() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments