Skip to content

Commit

Permalink
change name from test.lua to val.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
kenshohara committed Aug 24, 2017
1 parent f862e3c commit 96e6116
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 53 deletions.
6 changes: 3 additions & 3 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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

Expand Down
82 changes: 41 additions & 41 deletions opts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 {})

Expand Down
18 changes: 9 additions & 9 deletions test.lua → val.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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
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
Expand All @@ -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()
Expand All @@ -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)

Expand Down Expand Up @@ -69,7 +69,7 @@ function test_epoch()

return inputs, targets
end,
test_batch
val_batch
)
end

Expand All @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 96e6116

Please sign in to comment.