mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
Minor fix
This commit is contained in:
@ -476,6 +476,7 @@ void validate_detector(char *datacfg, char *cfgfile, char *weightfile, char *out
|
||||
float nms = .45;
|
||||
|
||||
int nthreads = 4;
|
||||
if (m < 4) nthreads = m;
|
||||
image *val = calloc(nthreads, sizeof(image));
|
||||
image *val_resized = calloc(nthreads, sizeof(image));
|
||||
image *buf = calloc(nthreads, sizeof(image));
|
||||
|
@ -277,9 +277,10 @@ void test_char_rnn(char *cfgfile, char *weightfile, int num, char *seed, float t
|
||||
for(j = 0; j < inputs; ++j){
|
||||
if (out[j] < .0001) out[j] = 0;
|
||||
}
|
||||
//c = sample_array(out, inputs);
|
||||
c = sample_array_custom(out, inputs);
|
||||
c = sample_array(out, inputs);
|
||||
//c = sample_array_custom(out, inputs);
|
||||
//c = max_index(out, inputs);
|
||||
//c = top_max_index(out, inputs, 2);
|
||||
print_symbol(c, tokens);
|
||||
}
|
||||
printf("\n");
|
||||
|
25
src/utils.c
25
src/utils.c
@ -654,6 +654,31 @@ int max_index(float *a, int n)
|
||||
return max_i;
|
||||
}
|
||||
|
||||
int top_max_index(float *a, int n, int k)
|
||||
{
|
||||
float *values = calloc(k, sizeof(float));
|
||||
int *indexes = calloc(k, sizeof(int));
|
||||
if (n <= 0) return -1;
|
||||
int i, j;
|
||||
for (i = 0; i < n; ++i) {
|
||||
for (j = 0; j < k; ++j) {
|
||||
if (a[i] > values[j]) {
|
||||
values[j] = a[i];
|
||||
indexes[j] = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
int count = 0;
|
||||
for (j = 0; j < k; ++j) if (values[j] > 0) count++;
|
||||
int get_index = rand_int(0, count-1);
|
||||
int val = indexes[get_index];
|
||||
free(indexes);
|
||||
free(values);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
int int_index(int *a, int val, int n)
|
||||
{
|
||||
int i;
|
||||
|
@ -59,6 +59,7 @@ void normalize_array(float *a, int n);
|
||||
void scale_array(float *a, int n, float s);
|
||||
void translate_array(float *a, int n, float s);
|
||||
int max_index(float *a, int n);
|
||||
int top_max_index(float *a, int n, int k);
|
||||
float constrain(float min, float max, float a);
|
||||
int constrain_int(int a, int min, int max);
|
||||
float mse_array(float *a, int n);
|
||||
|
Reference in New Issue
Block a user