-
Notifications
You must be signed in to change notification settings - Fork 0
/
Predictor.py
41 lines (36 loc) · 1.06 KB
/
Predictor.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
32
33
34
35
36
37
38
39
40
41
import tensorflow as tf
class Predictor:
def __init__(self, model,RESOLUTION):
self.resolution = RESOLUTION
self.model = model
with self.model.graph.as_default():
self.session = tf.Session()
def predict(self, image):
"""
Makes a prediction on image, outputs the probabilities of the labels
Parameters
-----
image : image
Returns
-----
logits: probabilities, output of the softamx layer
"""
return self.session.run(
fetches=self.model.prob,
feed_dict={
self.model.images:image.reshape(1,self.resolution,self.resolution,1)
}
)
def restore(self,path):
"""
Restores pretrained weights from the path
Parameters
-----
path : path to the weights
Returns
-----
None
"""
with self.model.graph.as_default():
saver = tf.train.Saver()
saver.restore(self.session, path)