Image-CCV
view release on metacpan or search on metacpan
ccv-src/lib/ccv_dpm.c view on Meta::CPAN
PRINT(CCV_CLI_INFO, "\n - aborting iteration at %d because we didn't gain much", t + 1);
break;
}
previous_positive_loss = positive_loss;
previous_negative_loss = negative_loss;
alpha *= params.alpha_ratio; // it will decrease with each iteration
}
_ccv_dpm_write_checkpoint(model, 0, checkpoint);
PRINT(CCV_CLI_INFO, "\n - data mining %d takes %.2lf seconds at loss %.5lf, %d more to go (%d of %d)\n", d + 1, (double)(_ccv_dpm_time_measure() - elapsed_time) / 1000000.0, loss, params.data_minings - d - 1, c + 1, params.relabels);
j = 0;
double* scores = (double*)ccmalloc(posnum * sizeof(double));
for (i = 0; i < posnum; i++)
if (posv[i])
{
scores[j] = _ccv_dpm_vector_score(model, posv[i]);
assert(!isnan(scores[j]));
j++;
}
_ccv_dpm_score_qsort(scores, j, 0);
ccfree(scores);
double breakdown;
PRINT(CCV_CLI_INFO, " - threshold breakdown by percentile");
for (breakdown = params.percentile_breakdown; breakdown < 1.0; breakdown += params.percentile_breakdown)
PRINT(CCV_CLI_INFO, " %0.2lf(%.1f%%)", scores[ccv_clamp((int)(breakdown * j), 0, j - 1)], (1.0 - breakdown) * 100);
PRINT(CCV_CLI_INFO, "\n");
char persist[512];
sprintf(persist, "%s/model.%d.%d", dir, c, d);
_ccv_dpm_write_checkpoint(model, 0, persist);
}
d = 0;
// if abort, means that we cannot find enough negative examples, try to adjust constant
for (i = 0; i < posnum; i++)
if (posv[i])
_ccv_dpm_feature_vector_free(posv[i]);
remove(feature_vector_checkpoint);
}
if (negv)
{
for (i = 0; i < negv->rnum; i++)
{
ccv_dpm_feature_vector_t* v = *(ccv_dpm_feature_vector_t**)ccv_array_get(negv, i);
_ccv_dpm_feature_vector_free(v);
}
ccv_array_free(negv);
}
remove(neg_vector_checkpoint);
ccfree(order);
ccfree(posv);
PRINT(CCV_CLI_INFO, "root rectangle prediction with linear regression\n");
_ccv_dpm_initialize_root_rectangle_estimator(model, posfiles, bboxes, posnum, params);
_ccv_dpm_write_checkpoint(model, 1, checkpoint);
PRINT(CCV_CLI_INFO, "done\n");
remove(gradient_progress_checkpoint);
_ccv_dpm_mixture_model_cleanup(model);
ccfree(model);
gsl_rng_free(rng);
}
#else
void ccv_dpm_mixture_model_new(char** posfiles, ccv_rect_t* bboxes, int posnum, char** bgfiles, int bgnum, int negnum, const char* dir, ccv_dpm_new_param_t params)
{
fprintf(stderr, " ccv_dpm_classifier_cascade_new requires libgsl and liblinear support, please compile ccv with them.\n");
}
#endif
#else
void ccv_dpm_mixture_model_new(char** posfiles, ccv_rect_t* bboxes, int posnum, char** bgfiles, int bgnum, int negnum, const char* dir, ccv_dpm_new_param_t params)
{
fprintf(stderr, " ccv_dpm_classifier_cascade_new requires libgsl and liblinear support, please compile ccv with them.\n");
}
#endif
static int _ccv_is_equal(const void* _r1, const void* _r2, void* data)
{
const ccv_root_comp_t* r1 = (const ccv_root_comp_t*)_r1;
const ccv_root_comp_t* r2 = (const ccv_root_comp_t*)_r2;
int distance = (int)(ccv_min(r1->rect.width, r1->rect.height) * 0.25 + 0.5);
return r2->rect.x <= r1->rect.x + distance &&
r2->rect.x >= r1->rect.x - distance &&
r2->rect.y <= r1->rect.y + distance &&
r2->rect.y >= r1->rect.y - distance &&
r2->rect.width <= (int)(r1->rect.width * 1.5 + 0.5) &&
(int)(r2->rect.width * 1.5 + 0.5) >= r1->rect.width &&
r2->rect.height <= (int)(r1->rect.height * 1.5 + 0.5) &&
(int)(r2->rect.height * 1.5 + 0.5) >= r1->rect.height;
}
static int _ccv_is_equal_same_class(const void* _r1, const void* _r2, void* data)
{
const ccv_root_comp_t* r1 = (const ccv_root_comp_t*)_r1;
const ccv_root_comp_t* r2 = (const ccv_root_comp_t*)_r2;
int distance = (int)(ccv_min(r1->rect.width, r1->rect.height) * 0.25 + 0.5);
return r2->classification.id == r1->classification.id &&
r2->rect.x <= r1->rect.x + distance &&
r2->rect.x >= r1->rect.x - distance &&
r2->rect.y <= r1->rect.y + distance &&
r2->rect.y >= r1->rect.y - distance &&
r2->rect.width <= (int)(r1->rect.width * 1.5 + 0.5) &&
(int)(r2->rect.width * 1.5 + 0.5) >= r1->rect.width &&
r2->rect.height <= (int)(r1->rect.height * 1.5 + 0.5) &&
(int)(r2->rect.height * 1.5 + 0.5) >= r1->rect.height;
}
ccv_array_t* ccv_dpm_detect_objects(ccv_dense_matrix_t* a, ccv_dpm_mixture_model_t** _model, int count, ccv_dpm_param_t params)
{
int c, i, j, k, x, y;
double scale = pow(2.0, 1.0 / (params.interval + 1.0));
int next = params.interval + 1;
int scale_upto = _ccv_dpm_scale_upto(a, _model, count, params.interval);
if (scale_upto < 0) // image is too small to be interesting
return 0;
ccv_dense_matrix_t** pyr = (ccv_dense_matrix_t**)alloca((scale_upto + next * 2) * sizeof(ccv_dense_matrix_t*));
_ccv_dpm_feature_pyramid(a, pyr, scale_upto, params.interval);
ccv_array_t* idx_seq;
ccv_array_t* seq = ccv_array_new(sizeof(ccv_root_comp_t), 64, 0);
ccv_array_t* seq2 = ccv_array_new(sizeof(ccv_root_comp_t), 64, 0);
ccv_array_t* result_seq = ccv_array_new(sizeof(ccv_root_comp_t), 64, 0);
for (c = 0; c < count; c++)
{
ccv_dpm_mixture_model_t* model = _model[c];
double scale_x = 1.0;
double scale_y = 1.0;
for (i = next; i < scale_upto + next * 2; i++)
{
for (j = 0; j < model->count; j++)
{
ccv_dpm_root_classifier_t* root = model->root + j;
( run in 0.750 second using v1.01-cache-2.11-cpan-5837b0d9d2c )