Skip to content

Commit

Permalink
make OPENCV compile again
Browse files Browse the repository at this point in the history
  • Loading branch information
uecker committed Jun 28, 2024
1 parent bccff2d commit c1b4462
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 28 deletions.
15 changes: 10 additions & 5 deletions src/classifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus,
int i;

float avg_loss = -1;
//float avg_contrastive_acc = 0;
#ifdef OPENCV
float avg_contrastive_acc = 0;
#endif
char *base = basecfg(cfgfile);
printf("%s\n", base);
printf("%d\n", ngpus);
Expand Down Expand Up @@ -186,8 +188,9 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus,
else fprintf(stderr, " Tensor Cores are used.\n");
}
}

//int draw_precision = 0;
#ifdef OPENCV
int draw_precision = 0;
#endif
if (calc_topk && (i >= calc_topk_for_each || i == net.max_batches)) {
iter_topk = i;
if (net.contrastive && l.type != SOFTMAX && l.type != COST) {
Expand All @@ -200,7 +203,9 @@ void train_classifier(char *datacfg, char *cfgfile, char *weightfile, int *gpus,
topk = validate_classifier_single(datacfg, cfgfile, weightfile, &net, topk_data); // calc TOP-n
printf("\n accuracy %s = %f \n", topk_buff, topk);
}
// draw_precision = 1;
#ifdef OPENCV
draw_precision = 1;
#endif
}

time_remaining = ((net.max_batches - i) / ngpus) * (what_time_is_it_now() - start) / 60 / 60;
Expand Down Expand Up @@ -1280,7 +1285,7 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind
int frame_counter = 0;

while(1){
struct timeval tval_before, tval_after, tval_result;
struct timeval tval_before /*, tval_after, tval_result */;
gettimeofday(&tval_before, NULL);

//image in = get_image_from_stream(cap);
Expand Down
12 changes: 6 additions & 6 deletions src/connected_layer.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,6 @@ void forward_connected_layer_gpu(connected_layer l, network_state state)
{
fill_ongpu(l.outputs*l.batch, 0, l.output_gpu, 1);

// int m = l.batch;
// int k = l.inputs;
// int n = l.outputs;
// float * a = state.input;
// float * b = l.weights_gpu;
// float * c = l.output_gpu;
#ifdef CUDNN
//float one = 1; // alpha[0], beta[0]
float alpha = 1, beta = 0;
Expand All @@ -360,6 +354,12 @@ void forward_connected_layer_gpu(connected_layer l, network_state state)
l.dstTensorDesc,
l.output_gpu));
#else // CUDNN
int m = l.batch;
int k = l.inputs;
int n = l.outputs;
float * a = state.input;
float * b = l.weights_gpu;
float * c = l.output_gpu;
gemm_ongpu(0,1,m,n,k,1,a,k,b,k,1,c,n);
#endif // CUDNN

Expand Down
6 changes: 3 additions & 3 deletions src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ data load_data_detection(int n, char **paths, int m, int w, int h, int c, int bo
d.X.vals = (float**)xcalloc(d.X.rows, sizeof(float*));
d.X.cols = h*w*c;

float r1 = 0, r2 = 0, r3 = 0, r4 = 0, r_scale = 0;
float r1 = 0, r2 = 0, r3 = 0, r4 = 0; //, r_scale = 0;
float resize_r1 = 0, resize_r2 = 0;
float dhue = 0, dsat = 0, dexp = 0, flip = 0, blur = 0;
int augmentation_calculated = 0, gaussian_noise = 0;
Expand Down Expand Up @@ -1134,7 +1134,7 @@ data load_data_detection(int n, char **paths, int m, int w, int h, int c, int bo
flip = use_flip ? random_gen() % 2 : 0;
}

r_scale = random_float();
//r_scale = random_float();

if (!contrastive || contrastive_color || i % 2 == 0)
{
Expand Down Expand Up @@ -1288,7 +1288,7 @@ data load_data_detection(int n, char **paths, int m, int w, int h, int c, int bo
const int bot_shift = min_val_cmp(h - cut_y[i], max_val_cmp(0, (-pbot*h / oh)));


int k, x, y;
int k, y;
for (k = 0; k < c; ++k) {
for (y = 0; y < h; ++y) {
int j = y*w + k*w*h;
Expand Down
2 changes: 1 addition & 1 deletion src/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void *detect_in_thread(void *ptr)
this_thread_yield();
}

layer l = net.layers[net.n - 1];
// layer l = net.layers[net.n - 1];
float *X = det_s.data;
//float *prediction =
network_predict(net, X);
Expand Down
19 changes: 12 additions & 7 deletions src/detector.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
char *base = basecfg(cfgfile);
printf("%s\n", base);
float avg_loss = -1;
// float avg_contrastive_acc = 0;
#ifdef OPENCV
float avg_contrastive_acc = 0;
#endif
network* nets = (network*)xcalloc(ngpus, sizeof(network));

srand(time(0));
Expand Down Expand Up @@ -324,7 +326,9 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
}
printf("\n %d: %f, %f avg loss, %f rate, %lf seconds, %d images, %f hours left\n", iteration, loss, avg_loss, get_current_rate(net), (what_time_is_it_now() - time), iteration*imgs, avg_time);
fflush(stdout);

#ifdef OPENCV
int draw_precision = 0;
#endif
if (calc_map && (iteration >= next_map_calc || iteration == net.max_batches)) {
if (l.random) {
printf("Resizing to initial size: %d x %d ", init_w, init_h);
Expand Down Expand Up @@ -370,8 +374,9 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
sprintf(buff, "%s/%s_best.weights", backup_directory, base);
save_weights(net, buff);
}

// draw_precision = 1;
#ifdef OPENCV
draw_precision = 1;
#endif
}
time_remaining = ((net.max_batches - iteration) / ngpus)*(what_time_is_it_now() - time + load_time) / 60 / 60;
// set initial value, even if resume training from 10000 iteration
Expand Down Expand Up @@ -1799,14 +1804,14 @@ void draw_object(char *datacfg, char *cfgfile, char *weightfile, char *filename,
}

srand(2222222);
char buff[256];
char buff[256] = { 0 };
char *input = buff;

int j;
float nms = .45; // 0.4F
while (1) {
if (filename) {
strncpy(input, filename, 256);
strncpy(input, filename, sizeof buff - 1);
if (strlen(input) > 0)
if (input[strlen(input) - 1] == 0x0d) input[strlen(input) - 1] = 0;
}
Expand Down Expand Up @@ -1868,7 +1873,7 @@ void draw_object(char *datacfg, char *cfgfile, char *weightfile, char *filename,
float avg_loss = get_network_cost(net);
draw_train_loss(windows_name, img, img_size, avg_loss, max_img_loss, iteration, it_num, 0, 0, "mAP%", 0, dont_show, 0, 0);

float inv_loss = 1.0 / max_val_cmp(0.01, avg_loss);
//float inv_loss = 1.0 / max_val_cmp(0.01, avg_loss);
//net.learning_rate = *lr_set * inv_loss;

if (*boxonly) {
Expand Down
2 changes: 1 addition & 1 deletion src/http_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ class MJPG_sender
#endif
if (s == sock) // request on master socket, accept and send main header.
{
SOCKADDR_IN address = { 0 };
SOCKADDR_IN address = { };
SOCKET client = ::accept(sock, (SOCKADDR*)&address, &addrlen);
if (client == SOCKET_ERROR)
{
Expand Down
12 changes: 7 additions & 5 deletions src/image_opencv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,13 +942,15 @@ extern "C" void draw_detections_cv_v3(mat_cv* mat, detection *dets, int num, flo
float red = get_color(2, offset, classes);
float green = get_color(1, offset, classes);
float blue = get_color(0, offset, classes);
#if 0
float rgb[3];

//width = prob*20+2;

rgb[0] = red;
rgb[1] = green;
rgb[2] = blue;
#endif
box b = dets[i].bbox;
if (std::isnan(b.w) || std::isinf(b.w)) b.w = 0.5;
if (std::isnan(b.h) || std::isinf(b.h)) b.h = 0.5;
Expand Down Expand Up @@ -1416,18 +1418,18 @@ extern "C" void cv_draw_object(image sized, float *truth_cpu, int max_boxes, int

int it_trackbar_value = 200;
std::string const it_trackbar_name = "iterations";
int it_tb_res = cv::createTrackbar(it_trackbar_name, window_name, &it_trackbar_value, 1000);
(void)cv::createTrackbar(it_trackbar_name, window_name, &it_trackbar_value, 1000);

int lr_trackbar_value = 10;
std::string const lr_trackbar_name = "learning_rate exp";
int lr_tb_res = cv::createTrackbar(lr_trackbar_name, window_name, &lr_trackbar_value, 20);
(void)cv::createTrackbar(lr_trackbar_name, window_name, &lr_trackbar_value, 20);

int cl_trackbar_value = 0;
std::string const cl_trackbar_name = "class_id";
int cl_tb_res = cv::createTrackbar(cl_trackbar_name, window_name, &cl_trackbar_value, classes-1);
(void)cv::createTrackbar(cl_trackbar_name, window_name, &cl_trackbar_value, classes-1);

std::string const bo_trackbar_name = "box-only";
int bo_tb_res = cv::createTrackbar(bo_trackbar_name, window_name, boxonly, 1);
(void)cv::createTrackbar(bo_trackbar_name, window_name, boxonly, 1);

int i = 0;

Expand All @@ -1440,7 +1442,7 @@ extern "C" void cv_draw_object(image sized, float *truth_cpu, int max_boxes, int
if (pressed_key == 27 || pressed_key == 1048603) break;// break; // ESC - save & exit

frame_clone = frame.clone();
char buff[100];
//char buff[100];
std::string lr_value = "learning_rate = " + std::to_string(1.0 / pow(2, lr_trackbar_value));
cv::putText(frame_clone, lr_value, cv::Point2i(10, 20), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(10, 50, 10), 3);
cv::putText(frame_clone, lr_value, cv::Point2i(10, 20), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(20, 120, 60), 2);
Expand Down

0 comments on commit c1b4462

Please sign in to comment.