(filenames, cifar_classnum)
| 38 | |
| 39 | |
| 40 | def read_cifar(filenames, cifar_classnum): |
| 41 | assert cifar_classnum == 10 or cifar_classnum == 100 |
| 42 | ret = [] |
| 43 | for fname in filenames: |
| 44 | fo = open(fname, 'rb') |
| 45 | dic = pickle.load(fo, encoding='bytes') |
| 46 | data = dic[b'data'] |
| 47 | if cifar_classnum == 10: |
| 48 | label = dic[b'labels'] |
| 49 | IMG_NUM = 10000 # cifar10 data are split into blocks of 10000 |
| 50 | else: |
| 51 | label = dic[b'fine_labels'] |
| 52 | IMG_NUM = 50000 if 'train' in fname else 10000 |
| 53 | fo.close() |
| 54 | for k in range(IMG_NUM): |
| 55 | img = data[k].reshape(3, 32, 32) |
| 56 | img = np.transpose(img, [1, 2, 0]) |
| 57 | ret.append([img, label[k]]) |
| 58 | return ret |
| 59 | |
| 60 | |
| 61 | def get_filenames(dir, cifar_classnum): |
no test coverage detected
searching dependent graphs…