diff --git a/mdata/ILSVRC.py b/mdata/ILSVRC.py index 0c62612..89f4dec 100644 --- a/mdata/ILSVRC.py +++ b/mdata/ILSVRC.py @@ -279,20 +279,21 @@ class DataILSVRC(DataDumperBase): W, H = size try: im = Image.open(image) + qt = im.quantization w, h = im.size if w < W or h < H: continue left, upper = random.randint(0, w - W), random.randint(0, h - H) im = im.crop((left, upper, left + W, upper + H)) - im.save(os.path.join(self.data_dir + '_crop_pil', name)) + im.save(os.path.join(self.data_dir + '_crop_pil', name), qtables=qt) except Exception as e: print '[EXCPT]', e pass # try: # img = cv2.imread(image, cv2.CV_LOAD_IMAGE_UNCHANGED) - # h, w = img.shape[:2] - # if w < 300 or h < 300: + # h, w = img.shape[:2] + # if w < 300 or h < 300: # continue # left, upper = random.randint(0, w - 300), random.randint(0, h - 300) # img_crop = img[upper:upper + 300, left:left + 300] @@ -453,7 +454,11 @@ class DataILSVRC(DataDumperBase): image = os.path.join(self.img_dir, hash[:3], hash[3:] + '.jpg') if image: im = Jpeg(image, key=sample_key) - dict_dataset[hash] = (tag, im.getCoefBlocks('Y')) + dict_dataset[hash] = (tag, im.getCoefMatrix(channel='Y')) + + for tag, feat in dict_dataset.values(): + X.append(feat.tolist()) + Y.append(int(tag)) else: with open(self.list_file, 'rb') as tsvfile: @@ -466,10 +471,10 @@ class DataILSVRC(DataDumperBase): with open(path_feat, 'rb') as featfile: dict_dataset[hash] = (tag, json.loads(featfile.read())) - for tag, feat in dict_dataset.values(): - # X.append([item for sublist in feat for subsublist in sublist for item in subsublist]) - X.append(np.array(feat).ravel().tolist()) - Y.append(int(tag)) + for tag, feat in dict_dataset.values(): + # X.append([item for sublist in feat for subsublist in sublist for item in subsublist]) + X.append(np.array(feat).ravel().tolist()) + Y.append(int(tag)) elif mode == "hbase": # remote if self.table == None: diff --git a/res/cropped_pil.jpg b/res/cropped_pil.jpg new file mode 100644 index 0000000..75327cd Binary files /dev/null and b/res/cropped_pil.jpg differ diff --git a/test/test_data.py b/test/test_data.py index 42b54f7..18ce805 100755 --- a/test/test_data.py +++ b/test/test_data.py @@ -115,6 +115,7 @@ def test_ILSVRC_S_SPARK(): dils._extract_feat(mode='spark', feattype='ibd', readforward=False, writeback=True, withdata=True) timer.report() + def test_ILSVRC_S(): # test_ILSVRC_S_LOCAL() test_ILSVRC_S_SPARK() @@ -137,17 +138,18 @@ def test_pipeline(): def test_crop(): # crop.crop_Test() - # dil = ILSVRC.DataILSVRC(base_dir='/data/hadoop/ImageNet/ILSVRC/ILSVRC2013_DET_val', category='Test_1') - # dil.crop() + dil = ILSVRC.DataILSVRC(base_dir='/data/hadoop/ImageNet/ILSVRC/ILSVRC2013_DET_val', category='Test_1') + dil.crop() dil2 = ILSVRC.DataILSVRC(base_dir='/data/hadoop/ImageNet/ILSVRC/ILSVRC2013_DET_val', category='Test_1_crop_pil') - # dil2.format() - # dil2.embed(rate=0.2) + dil2.format() + dil2.embed(rate=0.2) - X,Y = dil2.load_data(mode='local',feattype='coef') + X, Y = dil2.load_data(mode='local', feattype='coef') print X[0] print Y + print np.array(X).shape, np.array(Y).shape if __name__ == '__main__': diff --git a/test/test_jpeg.py b/test/test_jpeg.py index 9f7fd24..777cc72 100644 --- a/test/test_jpeg.py +++ b/test/test_jpeg.py @@ -151,7 +151,7 @@ def test_iter(): def test_jpeg(): - ima = mjpeg.Jpeg(os.path.join(package_dir, "../res/50c488a2b163ca8a1f52da6022f03.jpg"), key=sample_key) + ima = mjpeg.Jpeg(os.path.join(package_dir, "../res/cropped_pil.jpg"), key=sample_key) print ima.getQuality() print ima.getCapacity('All') sys.exit(0) -- libgit2 0.21.2