Created
August 9, 2017 10:20
-
-
Save beeva-albertorincon/c2d9f7cc7a51a2d6506812d6f96a14ca to your computer and use it in GitHub Desktop.
Stanford cars dataset extraction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding:utf8 | |
from scipy.io import loadmat | |
import pandas as pd | |
import numpy as np | |
mat_train = loadmat('devkit/cars_train_annos.mat') | |
mat_test = loadmat('devkit/cars_test_annos.mat') | |
meta = loadmat('devkit/cars_meta.mat') | |
labels = list() | |
for l in meta['class_names'][0]: | |
labels.append(l[0]) | |
train = list() | |
for example in mat_train['annotations'][0]: | |
label = labels[example[-2][0][0]-1] | |
image = example[-1][0] | |
train.append((image,label)) | |
test = list() | |
for example in mat_test['annotations'][0]: | |
image = example[-1][0] | |
test.append(image) | |
validation_size = int(len(train) * 0.10) | |
test_size = int(len(train) * 0.20) | |
validation = train[:validation_size].copy() | |
np.random.shuffle(validation) | |
train = train[validation_size:] | |
test = train[:test_size].copy() | |
np.random.shuffle(test) | |
train = train[test_size:] | |
# Google cloud example | |
bucket_path = 'gs://example' | |
with open('data/cars_data.csv', 'w+') as f: | |
[f.write('TRAIN,%s%s,%s\n' %(bucket_path,img,lab)) for img,lab in train] | |
[f.write('VALIDATION,%s%s,%s\n' %(bucket_path,img,lab)) for img,lab in validation] | |
[f.write('TEST,%s%s\n' %(bucket_path,img)) for img,_ in test] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment