Skip to content

Commit ab5c3be

Browse files
update
1 parent aa64da2 commit ab5c3be

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

play_with_api/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
car_images

play_with_api/ffmpeg.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import tensorflow as tf
2+
from tensorflow.contrib import ffmpeg
3+
4+
# tensorflow 1. 5 have decode_video ops. wait for reales of 1.5

play_with_api/tf_stack.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import tensorflow as tf
2+
import glob
3+
import gc
4+
# from memory_profiler import profile
5+
6+
7+
@profile
8+
def function_mark():
9+
pass
10+
11+
@profile
12+
def stack_images():
13+
image_file_list = glob.glob("car_images/*.jpg")
14+
sess = tf.Session()
15+
16+
for _ in range(300):
17+
# read image
18+
image1 = tf.gfile.FastGFile(image_file_list[0], 'rb').read()
19+
image2 = tf.gfile.FastGFile(image_file_list[1], 'rb').read()
20+
# decode image
21+
image1_decode = tf.image.decode_image(image1, channels=3)
22+
image2_decode = tf.image.decode_image(image2, channels=3)
23+
# stack image
24+
image_stack = tf.stack([image1_decode, image2_decode])
25+
# run session
26+
r_image_stack = sess.run(image_stack)
27+
# mark function. so I can check the memory-usage of every loop.
28+
function_mark()
29+
# force garbage collection, so all the un-reference variable will be freed.
30+
del r_image_stack
31+
gc.collect()
32+
33+
34+
35+
36+
if __name__ == "__main__":
37+
stack_images()
38+
39+
40+
def simple_example():
41+
x = tf.constant([1, 4])
42+
y = tf.constant([2, 5])
43+
z = tf.constant([3, 6])
44+
stack_1 = tf.stack([x, y, z]) # [[1, 4], [2, 5], [3, 6]] (Pack along first dim.)
45+
stack_2 = tf.stack([x, y, z], axis=1) # [[1, 2, 3], [4, 5, 6]]
46+
47+
sess = tf.Session()
48+
49+
r_stack_1, r_stack_2 = sess.run([stack_1, stack_2])
50+
51+
print(r_stack_1)
52+
print("=======================")
53+
print(r_stack_2)

0 commit comments

Comments
 (0)