|
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 | 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() |
|
0 commit comments