-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathdata_loader.py
64 lines (55 loc) · 2.58 KB
/
data_loader.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import tensorflow as tf
def read_and_decode(filename_queue, im_size=(512, 512, 1)):
writeOpts = tf.python_io.TFRecordOptions(\
tf.python_io.TFRecordCompressionType.ZLIB)
reader = tf.TFRecordReader(options=writeOpts)
_, single_example = reader.read(filename_queue)
features = tf.parse_single_example(
single_example,
features={
'frameA': tf.FixedLenFeature([], tf.string),
'frameB': tf.FixedLenFeature([], tf.string),
'amplified': tf.FixedLenFeature([], tf.string),
'amplification_factor': tf.FixedLenFeature([], tf.float32),
})
frameA = tf.decode_raw(features['frameA'], tf.uint8)
frameB = tf.decode_raw(features['frameB'], tf.uint8)
frameAmp = tf.decode_raw(features['amplified'], tf.uint8)
amplification_factor = tf.cast(features['amplification_factor'], tf.float32)
frameA = tf.reshape(frameA, im_size)
frameB = tf.reshape(frameB, im_size)
frameAmp = tf.reshape(frameAmp, im_size)
# Normalize to -1 to +1
frameA = tf.to_float(frameA) / 127.5 - 1.0
frameB = tf.to_float(frameB) / 127.5 - 1.0
frameAmp = tf.to_float(frameAmp) / 127.5 - 1.0
return frameA, frameB, frameAmp, amplification_factor
def read_and_decode_3frames(filename_queue, im_size=(512, 512, 1)):
writeOpts = tf.python_io.TFRecordOptions(\
tf.python_io.TFRecordCompressionType.ZLIB)
reader = tf.TFRecordReader(options=writeOpts)
_, single_example = reader.read(filename_queue)
features = tf.parse_single_example(
single_example,
features={
'frameA': tf.FixedLenFeature([], tf.string),
'frameB': tf.FixedLenFeature([], tf.string),
'frameC': tf.FixedLenFeature([], tf.string),
'amplified': tf.FixedLenFeature([], tf.string),
'amplification_factor': tf.FixedLenFeature([], tf.float32),
})
frameA = tf.decode_raw(features['frameA'], tf.uint8)
frameB = tf.decode_raw(features['frameB'], tf.uint8)
frameC = tf.decode_raw(features['frameC'], tf.uint8)
frameAmp = tf.decode_raw(features['amplified'], tf.uint8)
amplification_factor = tf.cast(features['amplification_factor'], tf.float32)
frameA = tf.reshape(frameA, im_size)
frameB = tf.reshape(frameB, im_size)
frameC = tf.reshape(frameC, im_size)
frameAmp = tf.reshape(frameAmp, im_size)
# Normalize to -1 to +1
frameA = tf.to_float(frameA) / 127.5 - 1.0
frameB = tf.to_float(frameB) / 127.5 - 1.0
frameC = tf.to_float(frameC) / 127.5 - 1.0
frameAmp = tf.to_float(frameAmp) / 127.5 - 1.0
return frameA, frameB, frameC, frameAmp, amplification_factor