{"nbformat": 4, "cells": [{"outputs": [], "cell_type": "code", "metadata": {"_uuid": "87a4fec5df9e66687290a0e95d6d3f18fd2e7f36", "collapsed": true, "_cell_guid": "06bb7f82-0d79-4112-b901-ce84030aade5"}, "execution_count": null, "source": ["import numpy as np\n", "import pandas as pd\n", "import io\n", "import bson\n", "import matplotlib.pyplot as plt\n", "from skimage.data import imread\n"]}, {"outputs": [], "cell_type": "code", "metadata": {"_uuid": "6a59d74d810ee35c12a8901331724cc250aa74f1", "collapsed": true, "_cell_guid": "008a2401-738a-45f9-9039-a1ba54b8577e"}, "execution_count": null, "source": ["categories = pd.read_csv('../input/category_names.csv', index_col='category_id')"]}, {"outputs": [], "cell_type": "code", "metadata": {"_uuid": "2e0391ebf0af8629bd7fcd03c818f5f4b775d24a", "_cell_guid": "7f0056ed-5228-4fd7-bb81-a33960c62bef"}, "execution_count": null, "source": ["rows, cols = 14, 8\n", "\n", "with open('../input/train_example.bson', 'rb') as f:\n", "    data = bson.decode_file_iter(f)\n", "    fig, ax = plt.subplots(rows, cols, figsize=(cols * 2, rows * 2))\n", "    ax = ax.ravel()\n", "    \n", "    i = 0\n", "    try:\n", "        for c, d in enumerate(data):\n", "            product_id = d['_id']\n", "            category_id = d['category_id']\n", "            for e, pic in enumerate(d['imgs']):\n", "                picture = imread(io.BytesIO(pic['picture']))\n", "                ax[i].imshow(picture)\n", "                ax[i].set_title(categories.loc[category_id, 'category_level3'][:12] + ' ('+ str(e) + ')')\n", "                i = i + 1\n", "        plt.tight_layout()\n", "        plt.show()\n", "                \n", "    except Exception as IndexError:\n", "        print(IndexError)"]}], "metadata": {"language_info": {"name": "python", "codemirror_mode": {"name": "ipython", "version": 3}, "nbconvert_exporter": "python", "version": "3.6.3", "mimetype": "text/x-python", "pygments_lexer": "ipython3", "file_extension": ".py"}, "kernelspec": {"name": "python3", "language": "python", "display_name": "Python 3"}}, "nbformat_minor": 1}