diff options
| author | adamhrv <adam@ahprojects.com> | 2018-12-17 01:37:31 +0100 |
|---|---|---|
| committer | adamhrv <adam@ahprojects.com> | 2018-12-17 01:37:31 +0100 |
| commit | 88ec48e1c4d93ba9cd3aa186c068ef2aa4c27c56 (patch) | |
| tree | 506075c0c8f0d4bbf15e97c6db50b6e055c5bd4e /megapixels/notebooks/_local_scratch.ipynb | |
| parent | 23e9fef5dce8b0b15dd94713816b9d7d45f12356 (diff) | |
fixing dataset procesosrs
Diffstat (limited to 'megapixels/notebooks/_local_scratch.ipynb')
| -rw-r--r-- | megapixels/notebooks/_local_scratch.ipynb | 196 |
1 files changed, 104 insertions, 92 deletions
diff --git a/megapixels/notebooks/_local_scratch.ipynb b/megapixels/notebooks/_local_scratch.ipynb index 167b6ddd..cee17cba 100644 --- a/megapixels/notebooks/_local_scratch.ipynb +++ b/megapixels/notebooks/_local_scratch.ipynb @@ -1,161 +1,173 @@ { "cells": [ { - "cell_type": "code", - "execution_count": 1, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "import pandas as pd\n", - "import cv2 as cv\n", - "import numpy as np\n", - "%matplotlib inline\n", - "import matplotlib.pyplot as plt" + "# Scratch pad" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "import sys\n", "from glob import glob\n", "from os.path import join\n", "from pathlib import Path\n", + "import random\n", + "\n", + "import pandas as pd\n", + "import cv2 as cv\n", + "import numpy as np\n", + "%matplotlib inline\n", + "import matplotlib.pyplot as plt\n", + "\n", + "import sys\n", "sys.path.append('/work/megapixels_dev/megapixels')\n", "from app.models.bbox import BBox\n", - "#from app.utils import im_utils\n", - "import random" + "from app.utils import im_utils, file_utils" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "dir_ims = '/data_store_ssd/apps/megapixels/datasets/umd_faces/faces/'" + "a= [1]" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n" - ] + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "fp_ims = glob(join(dir_ims, '*.png'))\n", - "print(len(fp_ims))" + "a[-1]" ] }, { "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Help on function choice in module random:\n", - "\n", - "choice(self, seq)\n", - " Choose a random element from a non-empty sequence.\n", - "\n" - ] - } - ], - "source": [ - "help(random.sample)" - ] - }, - { - "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 8, 0, 6, 3] True\n" - ] - } - ], - "source": [ - "a = list(range(0,10))\n", - "b = random.sample(a, 5)\n", - "print(b, len(set(b))==5)" - ] - }, - { - "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ - "from random import randint\n", - "imu" + "fp_filepath = '/data_store_ssd/datasets/people/lfw/metadata/filepath.csv'\n", + "df_filepath = pd.read_csv(fp_filepath)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, "outputs": [], "source": [ - "import face_alignment\n", - "from skimage import io\n", - "\n", - "fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._3D, flip_input=False, device='cuda')" + "image_index = 12467" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, - "outputs": [], - "source": [ - "fp_im = np.random.choice(fp_ims)\n", - "im = io.imread(fp_im)\n", - "preds = fa.get_landmarks(im)\n", - "print(preds[0])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12474\n" + ] + }, + { + "data": { + "text/plain": [ + "index 12851\n", + "ext jpg\n", + "fn Vladimir_Putin_0029\n", + "subdir Vladimir_Putin\n", + "Name: 12474, dtype: object" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "import json" + "image_index += 1\n", + "print(image_index)\n", + "df_filepath.iloc[image_index]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, "outputs": [], "source": [ - "print(len(preds[0]))\n" + "import imutils" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on function build_montages in module imutils.convenience:\n", + "\n", + "build_montages(image_list, image_shape, montage_shape)\n", + " ---------------------------------------------------------------------------------------------\n", + " author: Kyle Hounslow\n", + " ---------------------------------------------------------------------------------------------\n", + " Converts a list of single images into a list of 'montage' images of specified rows and columns.\n", + " A new montage image is started once rows and columns of montage image is filled.\n", + " Empty space of incomplete montage images are filled with black pixels\n", + " ---------------------------------------------------------------------------------------------\n", + " :param image_list: python list of input images\n", + " :param image_shape: tuple, size each image will be resized to for display (width, height)\n", + " :param montage_shape: tuple, shape of image montage (width, height)\n", + " :return: list of montage images in numpy array format\n", + " ---------------------------------------------------------------------------------------------\n", + " \n", + " example usage:\n", + " \n", + " # load single image\n", + " img = cv2.imread('lena.jpg')\n", + " # duplicate image 25 times\n", + " num_imgs = 25\n", + " img_list = []\n", + " for i in xrange(num_imgs):\n", + " img_list.append(img)\n", + " # convert image list into a montage of 256x256 images tiled in a 5x5 montage\n", + " montages = make_montages_of_images(img_list, (256, 256), (5, 5))\n", + " # iterate through montages and display\n", + " for montage in montages:\n", + " cv2.imshow('montage image', montage)\n", + " cv2.waitKey(0)\n", + " \n", + " ----------------------------------------------------------------------------------------------\n", + "\n" + ] + } + ], "source": [ - "with open('test.json', 'w') as fp:\n", - " json.dump(preds[0].tolist(), fp)" + "help(imutils.build_montages)" ] }, { @@ -182,7 +194,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.6" } }, "nbformat": 4, |
