In [53]:
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 [117]:
quantized_regions = np.load('pts_in_hull.npy')

In [150]:
QUANITZATION_SIZE=10

counts = collections.Counter()
greyscale = 0

def get_data(path):
  global counts, greyscale
  raw_image = io.imread(path)
  if raw_image.shape == (256,256,3):
    img = color.rgb2lab(raw_image)

    image = img[:,:,1:3]
    quantized_image = np.floor(image/10)*10
    
    for i, region in enumerate(quantized_regions):   
      counts[i]+= np.count_nonzero(quantized_image == region)
  else:
    greyscale += 1
    
get_data("/data/vision/torralba/yusuf/imagenet/data/images/train256/n03447447/n03447447_8414.JPEG")

In [ ]:
with open('all_paths.txt') as f:
  for i, path in enumerate(f):
    get_data(path.strip('\n'))
    if i%1000 == 0:
      print i
      
quantized_counts_as_array = list(counts.values())
np.save('quantized_counts.npy', quantized_counts_as_array)
print quantized_counts_as_array


0
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000
17000

In [141]:
a = [[[0, 10], [0, 10], [1, 10]]]
print a == [0, 10]
print np.count_nonzero(a == [0, 10])
print np.count_nonzero(a == [1, 10])


False
0
0