MCPcopy Create free account
hub / github.com/lazyprogrammer/machine_learning_examples / build

Method build

ann_class2/tf_with_save.py:29–51  ·  view source on GitHub ↗
(self, D, K)

Source from the content-addressed store, hash-verified

27 self.build(D, K)
28
29 def build(self, D, K):
30 W0 = np.random.randn(D, K) * np.sqrt(2.0 / D)
31 b0 = np.zeros(K)
32
33 # define variables and expressions
34 self.inputs = tf.placeholder(tf.float32, shape=(None, D), name='inputs')
35 self.targets = tf.placeholder(tf.int64, shape=(None,), name='targets')
36 self.W = tf.Variable(W0.astype(np.float32), name='W')
37 self.b = tf.Variable(b0.astype(np.float32), name='b')
38
39 # variables must exist when calling this
40 # try putting this line in the constructor and see what happens
41 self.saver = tf.train.Saver({'W': self.W, 'b': self.b})
42
43 logits = tf.matmul(self.inputs, self.W) + self.b
44 cost = tf.reduce_mean(
45 tf.nn.sparse_softmax_cross_entropy_with_logits(
46 logits=logits,
47 labels=self.targets
48 )
49 )
50 self.predict_op = tf.argmax(logits, 1)
51 return cost
52
53
54 def fit(self, X, Y, Xtest, Ytest):

Callers 2

__init__Method · 0.95
fitMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected