Skip to content

Commit

Permalink
more complete on help message of icfoptimize
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu committed Aug 27, 2013
1 parent e57a398 commit 71920ff
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 deletions.
35 changes: 15 additions & 20 deletions bin/icfoptimize.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ void exit_with_help()
{
printf(
"\n \033[1mUSAGE\033[0m\n\n icfoptimize [OPTION...]\n\n"
" \033[1mREQUIRED OPTIONS\033[0m\n\n"
" --positive-list : text file contains a list of positive files in format:\n"
" <file name> center-x center-y horizontal-axis-length vertical-axis-length object-roll object-pitch object-yaw \\newline\n"
" --acceptance : what percentage of positive examples that we should accept for soft cascading\n"
" --classifier-cascade : the model file that we will compute soft cascading thresholds on\n\n"
" \033[1mOTHER OPTIONS\033[0m\n\n"
" --base-dir : change the base directory so that the program can read images from there\n\n"
);
exit(-1);
}
Expand All @@ -17,20 +24,16 @@ int main(int argc, char** argv)
{"help", 0, 0, 0},
/* required parameters */
{"positive-list", 1, 0, 0},
{"working-dir", 1, 0, 0},
{"classifier-cascade", 1, 0, 0},
{"acceptance", 1, 0, 0},
/* optional parameters */
{"base-dir", 1, 0, 0},
{0, 0, 0, 0}
};
char* positive_list = 0;
char* working_dir = 0;
char* classifier_cascade = 0;
char* base_dir = 0;
double acceptance = 0;
ccv_icf_param_t detector = { .min_neighbors = 0, .flags = 0, .threshold = 0.0 };
ccv_icf_new_param_t params = {
.detector = detector,
};
int i, k;
while (getopt_long_only(argc, argv, "", icf_options, &k) != -1)
{
Expand All @@ -42,7 +45,7 @@ int main(int argc, char** argv)
positive_list = optarg;
break;
case 2:
working_dir = optarg;
classifier_cascade = optarg;
break;
case 3:
acceptance = atof(optarg);
Expand All @@ -53,7 +56,7 @@ int main(int argc, char** argv)
}
}
assert(positive_list != 0);
assert(working_dir != 0);
assert(classifier_cascade != 0);
ccv_enable_cache(512 * 1024 * 1024);
FILE* r0 = fopen(positive_list, "r");
assert(r0 && "positive-list doesn't exists");
Expand All @@ -78,18 +81,10 @@ int main(int argc, char** argv)
}
fclose(r0);
free(file);
params.grayscale = 0;
params.margin = ccv_margin(5, 5, 5, 5);
params.size = ccv_size(20, 60);
params.deform_shift = 0;
params.deform_angle = 0;
params.deform_scale = 0;
params.feature_size = 50000;
params.weak_classifier = 2000;
params.acceptance = acceptance;
ccv_icf_classifier_cascade_t* cascade = ccv_icf_read_classifier_cascade(working_dir);
ccv_icf_classifier_cascade_soft(cascade, posfiles, working_dir, params);
ccv_icf_write_classifier_cascade(cascade, working_dir);
ccv_icf_classifier_cascade_t* cascade = ccv_icf_read_classifier_cascade(classifier_cascade);
assert(cascade && "classifier cascade doesn't exists");
ccv_icf_classifier_cascade_soft(cascade, posfiles, classifier_cascade, acceptance);
ccv_icf_write_classifier_cascade(cascade, classifier_cascade);
for (i = 0; i < posfiles->rnum; i++)
{
ccv_file_info_t* file_info = (ccv_file_info_t*)ccv_array_get(posfiles, i);
Expand Down
7 changes: 7 additions & 0 deletions doc/icf.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,10 @@ How to train my own detector?

ccv provides utilities to train your own object models. Specifically, for ICF, these
utilities are available at ./bin/icfcreate and ./bin/icfoptimize.

./icfcreate --help

Will show you the parameters that ccv supports when training an object model.

If you have libdispatch installed and properly enabled on your machine, ccv will utilize
all your CPU cores to speed up the training process.
2 changes: 1 addition & 1 deletion lib/ccv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ void ccv_icf(ccv_dense_matrix_t* a, ccv_dense_matrix_t** b, int type);

/* ICF for single scale */
ccv_icf_classifier_cascade_t* __attribute__((warn_unused_result)) ccv_icf_classifier_cascade_new(ccv_array_t* posfiles, int posnum, ccv_array_t* bgfiles, int negnum, ccv_array_t* testfiles, const char* dir, ccv_icf_new_param_t params);
void ccv_icf_classifier_cascade_soft(ccv_icf_classifier_cascade_t* cascade, ccv_array_t* posfiles, const char* dir, ccv_icf_new_param_t params);
void ccv_icf_classifier_cascade_soft(ccv_icf_classifier_cascade_t* cascade, ccv_array_t* posfiles, const char* dir, double acceptance);
ccv_icf_classifier_cascade_t* __attribute__((warn_unused_result)) ccv_icf_read_classifier_cascade(const char* filename);
void ccv_icf_write_classifier_cascade(ccv_icf_classifier_cascade_t* classifier, const char* filename);
void ccv_icf_classifier_cascade_free(ccv_icf_classifier_cascade_t* classifier);
Expand Down
15 changes: 11 additions & 4 deletions lib/ccv_icf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1532,11 +1532,18 @@ ccv_icf_classifier_cascade_t* ccv_icf_classifier_cascade_new(ccv_array_t* posfil
return z.classifier;
}

void ccv_icf_classifier_cascade_soft(ccv_icf_classifier_cascade_t* cascade, ccv_array_t* posfiles, const char* dir, ccv_icf_new_param_t params)
void ccv_icf_classifier_cascade_soft(ccv_icf_classifier_cascade_t* cascade, ccv_array_t* posfiles, const char* dir, double acceptance)
{
printf("with %d positive examples\n"
"going to accept %.2lf%% positive examples\n",
posfiles->rnum, acceptance * 100);
ccv_size_t size = ccv_size(cascade->size.width - cascade->margin.left - cascade->margin.right, cascade->size.height - cascade->margin.top - cascade->margin.bottom);
printf("use color? %s\n", cascade->grayscale ? "no" : "yes");
printf("compute soft cascading thresholds for ICF classifier cascade at size %dx%d with margin (%d,%d,%d,%d)\n"
"------------------------\n",
size.width, size.height, cascade->margin.left, cascade->margin.top, cascade->margin.right, cascade->margin.bottom);
gsl_rng_env_setup();
gsl_rng* rng = gsl_rng_alloc(gsl_rng_default);
ccv_size_t size = ccv_size(cascade->size.width - cascade->margin.left - cascade->margin.right, cascade->size.height - cascade->margin.top - cascade->margin.bottom);
/* collect positives */
double weigh[2] = {
0, 0
Expand All @@ -1555,9 +1562,9 @@ void ccv_icf_classifier_cascade_soft(ccv_icf_classifier_cascade_t* cascade, ccv_
weak_classifier->weigh[0] = weak_classifier->weigh[0] * weigh[0];
weak_classifier->weigh[1] = weak_classifier->weigh[1] * weigh[1];
}
ccv_array_t* validates = _ccv_icf_collect_validates(rng, size, cascade->margin, posfiles, params.grayscale);
ccv_array_t* validates = _ccv_icf_collect_validates(rng, size, cascade->margin, posfiles, cascade->grayscale);
/* compute soft cascading thresholds */
_ccv_icf_classifier_cascade_soft_with_validates(validates, cascade, params.acceptance);
_ccv_icf_classifier_cascade_soft_with_validates(validates, cascade, acceptance);
ccv_array_free(validates);
gsl_rng_free(rng);
}
Expand Down

0 comments on commit 71920ff

Please sign in to comment.