def __init__(self, root, batch_size, train=False, input_size=224, **kwargs): self.mean = np.array([0.485, 0.456, 0.406]).reshape(1, 1, 1, 3) self.std = np.array([0.229, 0.224, 0.225]).reshape(1, 1, 1, 3) self.train = train if train: pkl_file = os.path.join(root, 'train{}.pkl'.format(input_size)) else: pkl_file = os.path.join(root, 'val{}.pkl'.format(input_size)) self.data_dict = misc.load_pickle(pkl_file) self.batch_size = batch_size self.idx = 0
from utee import misc import argparse import cv2 imagenet_urls = [ 'http://ml.cs.tsinghua.edu.cn/~chenxi/dataset/val224_compressed.pkl' ] parser = argparse.ArgumentParser( description='Extract the ILSVRC2012 val dataset') parser.add_argument('--in_file', default='./val224_compressed.pkl', help='input file path') parser.add_argument('--out_root', default='~/dataset', help='output file path') args = parser.parse_args() d = misc.load_pickle(args.in_file) assert len(d['data']) == 50000, len(d['data']) assert len(d['target']) == 50000, len(d['target']) data224 = [] data299 = [] for img, target in tqdm.tqdm(zip(d['data'], d['target']), total=1000): img224 = misc.str2img(img) #img299 = cv2.resize(img224, (299, 299)) data224.append(img224) #data299.append(img299) data_dict224 = dict(data=np.array(data224).transpose(0, 3, 1, 2), target=d['target']) #data_dict299 = dict( # data = np.array(data299).transpose(0, 3, 1, 2),
import os import numpy as np import tqdm from utee import misc import argparse import cv2 imagenet_urls = [ 'http://ml.cs.tsinghua.edu.cn/~chenxi/dataset/val224_compressed.pkl' ] parser = argparse.ArgumentParser(description='Extract the ILSVRC2012 val dataset') parser.add_argument('--in_file', default='val224_compressed.pkl', help='input file path') parser.add_argument('--out_root', default='/tmp/public_dataset/pytorch/imagenet-data/', help='output file path') args = parser.parse_args() d = misc.load_pickle(args.in_file) assert len(d['data']) == 50000, len(d['data']) assert len(d['target']) == 50000, len(d['target']) data224 = [] data299 = [] for img, target in tqdm.tqdm(zip(d['data'], d['target']), total=50000): img224 = misc.str2img(img) img299 = cv2.resize(img224, (299, 299)) data224.append(img224) data299.append(img299) data_dict224 = dict( data = np.array(data224).transpose(0, 3, 1, 2), target = d['target'] ) data_dict299 = dict(
#image.save("test_1.png", 'png') print(data0_to3) print("+++++") print(np.array(data0_to3).transpose(1, 2, 0)) # xx = -1/3 * math.log2(1/3) - 2/3 * math.log2(2/3) # xx1 = -1/5 * math.log2(1/5) - 4/5 * math.log2(4/5) # print(xx,xx1) from utee import misc from collections import Counter pkl_path = "../tmp/public_dataset/pytorch/imagenet-data/" d = misc.load_pickle(pkl_path + 'val224.pkl') data = d['data'] target = d['target'] print(len(data), len(target)) print(data[1].shape) print(target) result = Counter(target) print(result) for index, item in enumerate(data): if target[index] == 823: print("---") dt = np.array(item).transpose(1, 2, 0) cv2.imwrite("imagenet_" + str(index) + ".png", dt) # data2 = np.array(data[5]).transpose(1, 2, 0)