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
18000
19000
20000
21000
22000
23000
24000
25000
26000
27000
28000
29000
45000
46000
47000
48000
49000
50000
51000
52000
53000
54000
55000
56000
82000
83000
84000
85000
86000
87000
88000
89000
90000
91000
92000
93000
94000
95000
96000
97000
98000
99000
100000
101000
102000
103000
104000
105000
106000
107000
109000
110000
111000
112000
113000
114000
115000
116000
117000
118000
119000
120000

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