From 96e611613468db8837d53a1d801b2e7d93173598 Mon Sep 17 00:00:00 2001 From: Kensho Hara Date: Thu, 24 Aug 2017 15:10:40 +0900 Subject: [PATCH] change name from test.lua to val.lua --- main.lua | 6 ++-- opts.lua | 82 ++++++++++++++++++++++----------------------- test.lua => val.lua | 18 +++++----- 3 files changed, 53 insertions(+), 53 deletions(-) rename test.lua => val.lua (87%) diff --git a/main.lua b/main.lua index 1f25714..620b2b8 100644 --- a/main.lua +++ b/main.lua @@ -44,8 +44,8 @@ if not opt.no_train then dofile('train.lua') end -if not opt.no_test then - dofile('test.lua') +if not opt.no_val then + dofile('val.lua') end print('run') @@ -64,7 +64,7 @@ for i = opt.begin_epoch, opt.n_epochs do train_epoch() end if not opt.no_test then - test_epoch() + val_epoch() end end diff --git a/opts.lua b/opts.lua index 5669117..22506ab 100644 --- a/opts.lua +++ b/opts.lua @@ -2,47 +2,47 @@ local opts = {} -- parameters and others config function opts.parse(arg) local cmd = torch.CmdLine() - cmd:option('--root_path', '', 'Root directory path of data.') - cmd:option('--video_path', '', 'Directory path of Videos') - cmd:option('--annotation_path', '', 'Annotation file path') - cmd:option('--premodel_path', '', 'Pretrained model file path') - cmd:option('--bgr_premodel', false, 'If true then the pretrained model is bgr else rgb') - cmd:option('--result_path', 'results', 'Result directory path') - cmd:option('--dataset', 'activitynet', 'Name of the dataset (activitynet | kinetics)') - cmd:option('--lr_path', 'File path of learning rate scheduling. If \'\' then lr_path = result_path/lr.lua') - cmd:option('--n_classes', 200, 'Number of classes') - cmd:option('--sample_size', 112, 'Height and width of inputs') - cmd:option('--sample_duration', 16, 'Temporal duration of inputs') - cmd:option('--initial_scale', 1.0, 'Initial scale for multiscale cropping') - cmd:option('--n_scales', 5, 'Number of scales for multiscale cropping') - cmd:option('--scale_step', 0.84089641525, 'Scale step for multiscale cropping') - cmd:option('--learning_rate', 1e-3, 'Learning rate. If learning rate scheduling by lr_path is enabled, this is ignored.') - cmd:option('--weight_decay', 0.0, 'Weight decay. If learning rate scheduling by lr_path is enabled, this is ignored.') - cmd:option('--momentum', 0.9, 'Momentum.') - cmd:option('--dropout_ratio', 0.5, 'Dropout ratio') - cmd:option('--batch_size', 40, 'Batch Size') - cmd:option('--n_epochs', 1000, 'Number of total epochs to run') - cmd:option('--begin_epoch', 1, 'Training begins at this epoch. Previous trained model at result_path is loaded.') - cmd:option('--n_val_samples', 3, 'Number of validation samples for each activity') - cmd:option('--no_train', false, 'If true training is not performed.') - cmd:option('--no_test', false, 'If true testing is not performed.') - cmd:option('--test_video', false, 'If true testing on each video is performed.') - cmd:option('--no_cuda', false, 'If true cuda is not used') - cmd:option('--gpu_id', 1, 'ID of GPU to use') - cmd:option('--n_gpus', 2, 'Number of GPUs to use') - cmd:option('--n_threads', 4, 'Number of threads for multi-thread loading') - cmd:option('--checkpoint', 10, 'Trained model is saved at every this epochs.') - cmd:option('--manual_seed', 0, 'Manually set random seed') - cmd:option('--crop', 'c', 'Spatial cropping method. random is uniform. corner is selection from 4 corners and 1 cetner. (r | c)') - cmd:option('--no_hflip', false, 'If true holizontal flipping is not performed.') - cmd:option('--batch_norm', false, 'If true batch normalization is added to C3D') - cmd:option('--global_pooling', false, 'If true global average pooling is added to C3D') - cmd:option('--model', 'c3d', 'Network model (c3d | resnet)') - cmd:option('--resnet_depth', 18, 'Depth of resnet (10 | 18 | 34 | 50 | 101 | 152)') - cmd:option('--shortcut_type', 'A', 'Shortcut type of resnet (A | B | C)') - cmd:option('--weight_init', false, 'Weight initialization for resnet') - cmd:option('--test_subset', 'val', 'Subset to use for test_video (val | test)') - cmd:option('--freeze_params', 0, '0 means all layers are trained. 1 means last layer is trained.') + cmd:option('--root_path', '', 'Root directory path of data.') + cmd:option('--video_path', '', 'Directory path of Videos') + cmd:option('--annotation_path', '', 'Annotation file path') + cmd:option('--premodel_path', '', 'Pretrained model file path') + cmd:option('--bgr_premodel', false, 'If true then the pretrained model is bgr else rgb') + cmd:option('--result_path', 'results', 'Result directory path') + cmd:option('--dataset', 'activitynet', 'Name of the dataset (activitynet | kinetics)') + cmd:option('--lr_path', 'File path of learning rate scheduling. If \'\' then lr_path = result_path/lr.lua') + cmd:option('--n_classes', 200, 'Number of classes') + cmd:option('--sample_size', 112, 'Height and width of inputs') + cmd:option('--sample_duration', 16, 'Temporal duration of inputs') + cmd:option('--initial_scale', 1.0, 'Initial scale for multiscale cropping') + cmd:option('--n_scales', 5, 'Number of scales for multiscale cropping') + cmd:option('--scale_step', 0.84089641525, 'Scale step for multiscale cropping') + cmd:option('--learning_rate', 1e-3, 'Learning rate. If learning rate scheduling by lr_path is enabled, this is ignored.') + cmd:option('--weight_decay', 0.0, 'Weight decay. If learning rate scheduling by lr_path is enabled, this is ignored.') + cmd:option('--momentum', 0.9, 'Momentum.') + cmd:option('--dropout_ratio', 0.5, 'Dropout ratio') + cmd:option('--batch_size', 40, 'Batch Size') + cmd:option('--n_epochs', 1000, 'Number of total epochs to run') + cmd:option('--begin_epoch', 1, 'Training begins at this epoch. Previous trained model at result_path is loaded.') + cmd:option('--n_val_samples', 3, 'Number of validation samples for each activity') + cmd:option('--no_train', false, 'If true training is not performed.') + cmd:option('--no_val', false, 'If true validation is not performed.') + cmd:option('--test_video', false, 'If true testing for each video is performed.') + cmd:option('--no_cuda', false, 'If true cuda is not used') + cmd:option('--gpu_id', 1, 'ID of GPU to use') + cmd:option('--n_gpus', 2, 'Number of GPUs to use') + cmd:option('--n_threads', 4, 'Number of threads for multi-thread loading') + cmd:option('--checkpoint', 10, 'Trained model is saved at every this epochs.') + cmd:option('--manual_seed', 0, 'Manually set random seed') + cmd:option('--crop', 'c', 'Spatial cropping method. random is uniform. corner is selection from 4 corners and 1 cetner. (r | c)') + cmd:option('--no_hflip', false, 'If true holizontal flipping is not performed.') + cmd:option('--batch_norm', false, 'If true batch normalization is added to C3D') + cmd:option('--global_pooling', false, 'If true global average pooling is added to C3D') + cmd:option('--model', 'c3d', 'Network model (c3d | resnet)') + cmd:option('--resnet_depth', 18, 'Depth of resnet (10 | 18 | 34 | 50 | 101 | 152)') + cmd:option('--shortcut_type', 'A', 'Shortcut type of resnet (A | B | C)') + cmd:option('--weight_init', false, 'Weight initialization for resnet') + cmd:option('--test_subset', 'val', 'Subset to use for test_video (val | test)') + cmd:option('--freeze_params', 0, '0 means all layers are trained. 1 means last layer is trained.') local opt = cmd:parse(arg or {}) diff --git a/test.lua b/val.lua similarity index 87% rename from test.lua rename to val.lua index 924eae0..0988588 100644 --- a/test.lua +++ b/val.lua @@ -1,4 +1,4 @@ -test_logger = optim.Logger(paths.concat(opt.result_path, 'test.log')) +val_logger = optim.Logger(paths.concat(opt.result_path, 'val.log')) local batch_number local loss @@ -6,7 +6,7 @@ local acc local epoch_size local timer = torch.Timer() -local function prepare_test_batch() +local function prepare_val_batch() local sample_validation_data = {} for i = 1, #validation_data do local video_directory_path = validation_data[i].video @@ -28,7 +28,7 @@ local function prepare_test_batch() return sample_validation_data end -function test_epoch() +function val_epoch() batch_number = 0 if not opt.no_cuda then cutorch.synchronize() @@ -37,7 +37,7 @@ function test_epoch() model:evaluate() print('==> validation epoch # ' .. epoch) - local sample_validation_data = prepare_test_batch() + local sample_validation_data = prepare_val_batch() local n_samples = #sample_validation_data epoch_size = math.ceil(n_samples / opt.batch_size) @@ -69,7 +69,7 @@ function test_epoch() return inputs, targets end, - test_batch + val_batch ) end @@ -81,13 +81,13 @@ function test_epoch() loss = loss / epoch_size acc = acc / n_samples - test_logger:add{ + val_logger:add{ ['epoch'] = epoch, ['loss'] = loss, ['acc'] = acc, ['lr'] = optim_state.learningRate } - print(string.format('Epoch: [%d][TESTING SUMMARY] Total Time(s): %.2f \t Loss: %.2f \t Acc: %.3f\n', + print(string.format('Epoch: [%d][VALIDATION SUMMARY] Total Time(s): %.2f \t Loss: %.2f \t Acc: %.3f\n', epoch, timer:time().real, loss, acc)) end @@ -98,7 +98,7 @@ if not opt.no_cuda then targets = torch.CudaTensor() end -function test_batch(inputs_cpu, targets_cpu) +function val_batch(inputs_cpu, targets_cpu) if not opt.no_cuda then inputs:resize(inputs_cpu:size()):copy(inputs_cpu) targets:resize(targets_cpu:size()):copy(targets_cpu) @@ -131,6 +131,6 @@ function test_batch(inputs_cpu, targets_cpu) end batch_number = batch_number + 1 - print(string.format('Epoch: Testing [%d][%d/%d] \t Loss %.4f \t Acc %.3f', epoch, batch_number, epoch_size, loss_batch, acc_batch)) + print(string.format('Epoch: Validation [%d][%d/%d] \t Loss %.4f \t Acc %.3f', epoch, batch_number, epoch_size, loss_batch, acc_batch)) collectgarbage() end