MCPcopy
hub / github.com/MrNothing/AI-Blocks / Run

Function Run

Sources/templates/classifier_template.py:22–65  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

20save_path = ""
21
22def Run(self):
23
24 ### defining the model: ###
25
26 #inputs:
27 self.X = tf.placeholder(tf.float32, shape=[None, self._input.input_size], name="x_input")
28 self.y = tf.placeholder(tf.float32, shape=[None, self._input.labels_size], name="y_labels")
29
30 # ouput:
31 output = self._model.Run(self.X)
32
33 #Loss function
34 _loss = tf.reduce_mean(tf.pow(output-self.y, 2))
35
36 #measure the accuracy
37 correct_pred = tf.equal(tf.argmax(output, 1), tf.argmax(self.y, 1))
38 _accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
39
40 #run the optimizer
41 _solver = tf.train.AdamOptimizer(self.learning_rate).minimize(_loss)
42
43 #initalize everything
44 instance = AIBlocks.InitModel(load_path=self.save_path)
45 Log("Model initialized!")
46
47 #set the progress bar state
48 SetState(self.id, 0.001)
49
50 for it in range(self.training_iterations):
51 batch = self._input.getNextBatch()
52
53 X_batch = batch[0]
54 Y_batch = batch[1]
55
56 _, loss, acc = instance.Run([_solver, _loss, _accuracy], feed_dict={self.X: X_batch, self.y: Y_batch})
57
58 #every N steps, send the state to the scene
59 if it % self.display_step == 0:
60 SetState(self.id, it/self.training_iterations)
61 SendChartData(self.id, "Loss", loss, "#ff0000")
62 SendChartData(self.id, "Accuracy", acc)
63
64 AIBlocks.SaveModel(instance)
65 AIBlocks.CloseInstance(instance)
66

Callers

nothing calls this directly

Calls 7

LogFunction · 0.85
SetStateFunction · 0.85
SendChartDataFunction · 0.85
InitModelMethod · 0.80
SaveModelMethod · 0.80
CloseInstanceMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected