-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathInfer.py
More file actions
36 lines (28 loc) · 1.3 KB
/
Copy pathInfer.py
File metadata and controls
36 lines (28 loc) · 1.3 KB
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
import tensorflow as tf
from tqdm import tqdm
import os
from Data import Data
from Model import Model
class Infer:
def __init__(self, params):
self._batch_size = params['BATCH_SIZE']
self.data = Data(params)
self.model = Model(params)
def infer(self):
with tf.Session() as sess:
sess.run([tf.global_variables_initializer(), tf.tables_initializer()])
self.model.dataset.initialize_iterator(sess, self.data.infer_files)
try:
with tqdm(total=self.data.get_infer_data_length()) as pbar:
while True:
top_pred, file_path = sess.run([self.model.top_prediction, self.model.dataset.file_path])
probabilities, class_ids = top_pred.values, top_pred.indices
for p, c, fp in zip(probabilities, class_ids, file_path):
fp = os.path.basename(fp.decode('ascii'))
print('File: ', fp)
for p_i, c_i in zip(p, c):
print('Class: {}, probability: {:.4f}'.format(self.data.classes[c_i], p_i))
print()
pbar.update(self._batch_size)
except tf.errors.OutOfRangeError:
pass