{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# LFW Visualize" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2\n", "\n", "import os\n", "from os.path import join\n", "import math\n", "from glob import glob\n", "from random import randint\n", "\n", "import cv2 as cv\n", "import numpy as np\n", "import pandas as pd\n", "from PIL import Image, ImageDraw\n", "%matplotlib inline\n", "import matplotlib.pyplot as plt\n", "import scipy.io\n", "from pathlib import Path\n", "from sklearn import preprocessing\n", "from tqdm import tqdm_notebook as tqdm\n", "\n", "import sys\n", "sys.path.append('/work/megapixels_dev/megapixels/')\n", "from app.settings import app_cfg as cfg\n", "from app.utils import file_utils\n", "from app.models.bbox import BBox" ] }, { "cell_type": "code", "execution_count": 124, "metadata": {}, "outputs": [], "source": [ "# function to create spaced colormaps as RGB values\n", "\n", "import matplotlib as mpl\n", "import matplotlib.cm as mplcm\n", "import matplotlib.pyplot as plt\n", "from matplotlib import cm\n", "\n", "def get_color_map(cmap='prism', ncolors=20, as_hex=False, reverse=False, bgr=True):\n", " norm = mpl.colors.Normalize(vmin=0, vmax=ncolors-1)\n", " scalars = mplcm.ScalarMappable(norm=norm, cmap=cmap)\n", " colors = [scalars.to_rgba(i) for i in range(ncolors)]\n", " colors = [(int(255*c[0]),int(255*c[1]),int(255*c[2])) for c in colors] \n", " if reverse:\n", " colors = colors[::-1]\n", " if bgr:\n", " colors = [c[::-1] for c in colors]\n", " if as_hex:\n", " colors = ['#{:02x}{:02x}{:02x}'.format(c[0],c[1],c[2]) for c in colors]\n", " return colors\n", "\n", "def jitter_clr(clr, amt=10, mono=False):\n", " clr = list(clr)\n", " if mono:\n", " r = randint(-amt, amt)\n", " for i in range(len(clr)):\n", " clr[i] = max(0, min(255, clr[i] + r))\n", " else:\n", " for i in range(len(clr)):\n", " r = randint(-amt, amt)\n", " clr[i] = max(0, min(255, clr[i] + r))\n", " return clr\n", "\n", "def random_color():\n", " return tuple(map(int, np.random.choice(range(256), size=3)))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "DATA_STORE = '/data_store_nas/'\n", "fp_dataset = join(DATA_STORE, 'datasets/people/lfw')\n", "\n", "DATA_STORE_HDD = '/data_store_hdd/'\n", "fp_rois = join(DATA_STORE_HDD, 'apps/megapixels/datasets/people/lfw/rois.csv')" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | Unnamed: 0 | \n", "ext | \n", "fn | \n", "h | \n", "w | \n", "x | \n", "y | \n", "
|---|---|---|---|---|---|---|---|
| 0 | \n", "0 | \n", ".jpg | \n", "AJ_Cook_0001 | \n", "0.330000 | \n", "0.330000 | \n", "0.336667 | \n", "0.350000 | \n", "
| 1 | \n", "1 | \n", ".jpg | \n", "AJ_Lamas_0001 | \n", "0.393333 | \n", "0.393333 | \n", "0.286667 | \n", "0.313333 | \n", "
| 2 | \n", "2 | \n", ".jpg | \n", "Aaron_Eckhart_0001 | \n", "0.393333 | \n", "0.393333 | \n", "0.286667 | \n", "0.273333 | \n", "
| 3 | \n", "3 | \n", ".jpg | \n", "Aaron_Guiel_0001 | \n", "0.393333 | \n", "0.393333 | \n", "0.286667 | \n", "0.313333 | \n", "
| 4 | \n", "4 | \n", ".jpg | \n", "Aaron_Patterson_0001 | \n", "0.393333 | \n", "0.393333 | \n", "0.286667 | \n", "0.273333 | \n", "