| import pickle | |
| import json | |
| import numpy as np | |
| myfile = 'train_offset_5_test.pickle' | |
| #THUMOS : {video_validation_xx: {anno: , feature_length: } , video_validation_xxx : ,..} | |
| #anno shape : (feature_length, 22) | |
| objects = [] | |
| with (open(myfile, "rb")) as openfile: | |
| pickle = pickle.load(openfile) | |
| print(pickle["fc2b2014-9dc4-4a5d-8a1d-25a6911bff7c"]['anno'][100:200]) | |
| #print(pickle['604bf883-ce55-4c59-bcc1-3ceea1128211']) | |
| # outlier = {} | |
| # for uid in pickle : | |
| # all = 0 | |
| # both = 0 | |
| # one = 0 | |
| # last = np.array([1,0,0]) | |
| # annos = pickle[uid]['anno'] | |
| # for anno in annos : | |
| # all+=1 | |
| # if np.all(anno == np.array([0,1,1])) : | |
| # both +=1 | |
| # elif np.all(last == np.array([0,0,1])) and np.all(anno == np.array([0,1,0])) : | |
| # one +=1 | |
| # last = anno | |
| # outlier[uid] = {} | |
| # outlier[uid]['011'] = both | |
| # outlier[uid]['001and010'] = one | |
| # with open('outlier_train.json', 'w') as f : | |
| # json.dump(outlier, f, indent = 4) | |
| # with open('pickle_to_txt.txt', 'w') as f: | |
| # json.dump(objects, f, indent = '\t') | |
| # class NumpyEncoder(json.JSONEncoder): | |
| # """ Special json encoder for numpy types """ | |
| # def default(self, obj): | |
| # if isinstance(obj, np.integer): | |
| # return int(obj) | |
| # elif isinstance(obj, np.floating): | |
| # return float(obj) | |
| # elif isinstance(obj, np.ndarray): | |
| # return obj.tolist() | |
| # return json.JSONEncoder.default(self, obj) | |
| # dumped = json.dumps(pickle, cls=NumpyEncoder) | |
| # with open('pickle_to_json.json', 'w') as f: | |
| # json.dump(dumped, f) | |