forked from billy-inn/NFETC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
31 lines (24 loc) · 1.16 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Model(object):
def add_placeholders(self):
raise NotImplementedError("Each Model must re-implement this method.")
def create_feed_dict(self, inputs_batch, labels_batch=None):
raise NotImplementedError("Each Model must re-implement this method.")
def add_prediction_op(self):
raise NotImplementedError("Each Model must re-implement this method.")
def add_loss_op(self, pred):
raise NotImplementedError("Each Model must re-implement this method.")
def add_training_op(self, loss):
raise NotImplementedError("Each Model must re-implement this method.")
def train_on_batch(self, sess, inputs_batch, labels_batch):
feed = self.create_feed_dict(inputs_batch, labels_batch=labels_batch)
_, loss = sess.run([self.train_op, self.loss], feed_dict=feed)
return loss
def predict_on_batch(self, sess, inputs_batch):
feed = self.create_feed_dict(inputs_batch)
predictions = sess.run(self.pred, feed_dict=feed)
return predictions
def build(self):
self.add_placeholders()
self.add_prediction_op()
self.add_loss_op()
self.add_training_op()