forked from CMU-Perceptual-Computing-Lab/openpose_train
-
Notifications
You must be signed in to change notification settings - Fork 2
/
a_prepareTestDevFolder.m
54 lines (47 loc) · 1.79 KB
/
a_prepareTestDevFolder.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
%% Script splitting test2015/ images into test2015_dev/
clear variables; close all; clc
%% Time measurement
tic
%% Default paths
addpath('../matlab_utilities/')
yearString = '2017';
datasetPath = '../dataset/COCO/';
testDevFilePath = [datasetPath, 'cocoapi/annotations/image_info_test-dev', yearString, '.json'];
testFolder = [datasetPath, 'cocoapi/images/test', yearString, '/'];
testDevFolder = [datasetPath, 'cocoapi/images/test', yearString, '_dev/'];
%% Read JSON text
fileID = fopen(testDevFilePath);
formatSpec = '%s'; % Text Array
jsonTextString = fscanf(fileID, formatSpec);
%% JSON string to image paths
fprintf('JSON string to image paths...\n');
jsonStruct = jsondecode(jsonTextString);
jsonImagesStruct = jsonStruct.images;
imageFileNames = cell(numel(numel(jsonImagesStruct)), 1);
for imageIndex = 1:numel(jsonImagesStruct)
imageFileNames{imageIndex} = jsonImagesStruct(imageIndex).file_name;
end
%% Create testDevFolder
fprintf('Creating test dev folder...\n');
[status, msg, msgID] = mkdir(testDevFolder);
if status ~= 1
error(['Error when creating folder. Message: ', msg, '. Message ID: ', int2str(msgID)]);
end
%% Copy images
fprintf('Copying images...\n');
numberAnnotations = numel(imageFileNames);
logEveryXFrames = round(numberAnnotations / 50);
for imageIndex = 1:numel(imageFileNames)
fileName = imageFileNames{imageIndex};
imageTestPath = [testFolder, fileName];
imageTestDevPath = [testDevFolder, fileName];
[status, msg, msgID] = copyfile(imageTestPath, imageTestDevPath);
if status ~= 1
error(['Error when creating folder. Message: ', msg, '. Message ID: ', int2str(msgID)]);
end
% Display progress
progressDisplay(imageIndex, logEveryXFrames, numberAnnotations);
end
fprintf('\nFinished copying images!\n\n');
%% Time measurement
printToc(toc);