Last active
October 5, 2017 14:18
-
-
Save aoikonomop/56341119907fa2cc17e25652b26c9cf4 to your computer and use it in GitHub Desktop.
imageio vs pillow execution time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"INFO:root:Test\n" | |
] | |
} | |
], | |
"source": [ | |
"import os\n", | |
"import numpy as np\n", | |
"import time\n", | |
"import logging\n", | |
"import tensorflow as tf\n", | |
"\n", | |
"from hudl_beatrix.dataset import BrainWashDataset\n", | |
"\n", | |
"import matplotlib.pyplot as plt\n", | |
"import matplotlib.patches as patches\n", | |
"%matplotlib inline\n", | |
"\n", | |
"logging.info('Test')\n", | |
"logger = logging.getLogger()\n", | |
"logger.setLevel(logging.INFO)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"dataset_imageio = BrainWashDataset(image_method='imageio')\n", | |
"dataset_pillow_jpeg = BrainWashDataset(image_method='pillow', encoding='JPEG')\n", | |
"dataset_pillow_png = BrainWashDataset(image_method='pillow', encoding='PNG')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"ERROR:root:Directory already exists, no data will be converted! Did you mean to set the overwrite flag to True?\n", | |
"ERROR:root:Directory already exists, no data will be converted! Did you mean to set the overwrite flag to True?\n", | |
"ERROR:root:Directory already exists, no data will be converted! Did you mean to set the overwrite flag to True?\n" | |
] | |
} | |
], | |
"source": [ | |
"dataset_imageio.convert(dataset_path='./brainwash_tf_records_imageio')\n", | |
"dataset_pillow_jpeg.convert(dataset_path='./brainwash_tf_records_pillow_jpeg')\n", | |
"dataset_pillow_png.convert(dataset_path='./brainwash_tf_records_pillow_png')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"train_dir = './brainwash_tf_records_imageio/train'\n", | |
"records_imageio = [os.path.join(train_dir, record) for record in os.listdir(train_dir)]\n", | |
"train_dir = './brainwash_tf_records_pillow_jpeg/train'\n", | |
"records_pillow_jpeg = [os.path.join(train_dir, record) for record in os.listdir(train_dir)]\n", | |
"train_dir = './brainwash_tf_records_pillow_png/train'\n", | |
"records_pillow_png = [os.path.join(train_dir, record) for record in os.listdir(train_dir)]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"INFO:root:Imageio time : 12.12564206123352 sec\n", | |
"INFO:root:Pillow jpeg time : 12.177225112915039 sec\n", | |
"INFO:root:Pillow png time : 12.364830732345581 sec\n" | |
] | |
} | |
], | |
"source": [ | |
"n_threads = 8\n", | |
"batch_size = 1\n", | |
"min_after_dequeue = 8\n", | |
"\n", | |
"input_fn_imageio = dataset_imageio.input_fn(records_imageio, \n", | |
" batch_size=batch_size,\n", | |
" n_threads=n_threads,\n", | |
" min_after_dequeue=min_after_dequeue)\n", | |
"input_fn_pillow_jpeg = dataset_pillow_jpeg.input_fn(records_pillow_jpeg, \n", | |
" batch_size=batch_size,\n", | |
" n_threads=n_threads,\n", | |
" min_after_dequeue=min_after_dequeue)\n", | |
"input_fn_pillow_png = dataset_pillow_png.input_fn(records_pillow_png, \n", | |
" batch_size=batch_size,\n", | |
" n_threads=n_threads,\n", | |
" min_after_dequeue=min_after_dequeue)\n", | |
"\n", | |
"record_imageio = input_fn_imageio()\n", | |
"record_pillow_jpeg = input_fn_pillow_jpeg()\n", | |
"record_pillow_png = input_fn_pillow_png()\n", | |
"\n", | |
"imageio_time = 0\n", | |
"pillow_jpeg_time = 0\n", | |
"pillow_png_time = 0\n", | |
"\n", | |
"with tf.Session() as sess:\n", | |
" sess.run(tf.global_variables_initializer())\n", | |
"\n", | |
" coord = tf.train.Coordinator()\n", | |
" threads = tf.train.start_queue_runners(coord=coord)\n", | |
"\n", | |
" for i in range(len(records_imageio)):\n", | |
" start_time = time.time()\n", | |
" img, bx = sess.run(record_imageio)\n", | |
" imageio_time += time.time() - start_time\n", | |
" \n", | |
" start_time = time.time()\n", | |
" img, bx = sess.run(record_pillow_jpeg)\n", | |
" pillow_jpeg_time += time.time() - start_time\n", | |
" \n", | |
" start_time = time.time()\n", | |
" img, bx = sess.run(record_pillow_png)\n", | |
" pillow_png_time += time.time() - start_time\n", | |
"\n", | |
" coord.request_stop()\n", | |
" coord.join(threads)\n", | |
"\n", | |
"logger.info('Imageio time : {} sec'.format(imageio_time))\n", | |
"logger.info('Pillow jpeg time : {} sec'.format(pillow_jpeg_time))\n", | |
"logger.info('Pillow png time : {} sec'.format(pillow_png_time))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.5.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment