In [3]:
root = '/data/vision/torralba/health-habits/other/enes/'

%matplotlib inline
import matplotlib.pyplot as plt

import os
import sys
import random
import json
import collections
import math
import fnmatch
import os
import scipy.misc
sys.path.append( root + 'Utils/')

import pandas as pd
import numpy as np
import tensorflow as tf

from PIL import Image
from IPython.display import display
from pprint import pprint
from notebook_utils import *
from skimage import color, io

In [ ]:
def precompute_distributions():
  for a in range(-120, 120):
    for b in range(-120, 120):
      ab = (a, b)
      qab = (round(a/10)*10, round(b/10)*10)

In [6]:
def get_data(path):
  img = io.imread(path)
  img = color.rgb2lab(img)
  assert img.shape == (256,256,3)

  image = img[:,:,0:1]
  img = scipy.misc.imresize(img, (64,64))
  colors = img[:,:,1:3]
  quantized_array = np.tile( colors.reshape((64,64,1,2)), (1,1,313,1))
  print quantized_array.shape
  big_quantized = np.tile( quantized_array, (64,64,1,1))
  distances = np.linalg.norm(colors - big_quantized, axis = 3)
  d = distances.copy()
  d.sort(axis = 2)
  low_values = (distances > np.tile( d[:,:,4:5], (1,1,313) ))
  gaussian_distances = gaussian(distances, 5)
  gaussian_distances[low_values] = 0
  output = gaussian_distances / np.sum(gaussian_distances, axis = 2).reshape((64,64,1))
  
  return image, output

get_data("/data/vision/torralba/yusuf/imagenet/data/images/train256/n03447447/n03447447_8414.JPEG")


(64, 64, 313, 2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-0f5c74ca971f> in <module>()
     20   return image, output
     21 
---> 22 get_data("/data/vision/torralba/yusuf/imagenet/data/images/train256/n03447447/n03447447_8414.JPEG")

<ipython-input-6-0f5c74ca971f> in get_data(path)
     10   print quantized_array.shape
     11   big_quantized = np.tile( quantized_array, (64,64,1,1))
---> 12   distances = np.linalg.norm(colors - big_quantized, axis = 3)
     13   d = distances.copy()
     14   d.sort(axis = 2)

ValueError: operands could not be broadcast together with shapes (64,64,2) (4096,4096,313,2)