From 160eddddc4e265d5ee59a38797c30720bf46cd7c Mon Sep 17 00:00:00 2001
From: AlexeyAB <alexeyab84@gmail.com>
Date: Sun, 27 May 2018 13:53:42 +0000
Subject: [PATCH] Minor fix
---
src/classifier.c | 98 +++++++++++++++++++++++++++++++------------------
1 files changed, 62 insertions(+), 36 deletions(-)
diff --git a/src/classifier.c b/src/classifier.c
index 586530a..98dd4c6 100644
--- a/src/classifier.c
+++ b/src/classifier.c
@@ -6,11 +6,23 @@
#include "assert.h"
#include "classifier.h"
#include "cuda.h"
+#ifdef WIN32
+#include <time.h>
+#include <winsock.h>
+#include "gettimeofday.h"
+#else
#include <sys/time.h>
+#endif
#ifdef OPENCV
#include "opencv2/highgui/highgui_c.h"
+#include "opencv2/core/version.hpp"
+#ifndef CV_VERSION_EPOCH
+#include "opencv2/videoio/videoio_c.h"
+#endif
image get_image_from_stream(CvCapture *cap);
+image get_image_from_stream_cpp(CvCapture *cap);
+#include "http_stream.h"
#endif
float *get_regression_values(char **labels, int n)
@@ -77,6 +89,7 @@
args.min = net.min_crop;
args.max = net.max_crop;
+ args.flip = net.flip;
args.angle = net.angle;
args.aspect = net.aspect;
args.exposure = net.exposure;
@@ -183,6 +196,7 @@
args.min = net.min_crop;
args.max = net.max_crop;
+ args.flip = net.flip;
args.angle = net.angle;
args.aspect = net.aspect;
args.exposure = net.exposure;
@@ -352,11 +366,11 @@
int *indexes = calloc(topk, sizeof(int));
for(i = 0; i < m; ++i){
- int class = -1;
+ int class_id = -1;
char *path = paths[i];
for(j = 0; j < classes; ++j){
if(strstr(path, labels[j])){
- class = j;
+ class_id = j;
break;
}
}
@@ -386,9 +400,9 @@
free_image(im);
top_k(pred, classes, topk, indexes);
free(pred);
- if(indexes[0] == class) avg_acc += 1;
+ if(indexes[0] == class_id) avg_acc += 1;
for(j = 0; j < topk; ++j){
- if(indexes[j] == class) avg_topk += 1;
+ if(indexes[j] == class_id) avg_topk += 1;
}
printf("%d: top 1: %f, top %d: %f\n", i, avg_acc/(i+1), topk, avg_topk/(i+1));
@@ -425,11 +439,11 @@
int size = net.w;
for(i = 0; i < m; ++i){
- int class = -1;
+ int class_id = -1;
char *path = paths[i];
for(j = 0; j < classes; ++j){
if(strstr(path, labels[j])){
- class = j;
+ class_id = j;
break;
}
}
@@ -446,9 +460,9 @@
free_image(resized);
top_k(pred, classes, topk, indexes);
- if(indexes[0] == class) avg_acc += 1;
+ if(indexes[0] == class_id) avg_acc += 1;
for(j = 0; j < topk; ++j){
- if(indexes[j] == class) avg_topk += 1;
+ if(indexes[j] == class_id) avg_topk += 1;
}
printf("%d: top 1: %f, top %d: %f\n", i, avg_acc/(i+1), topk, avg_topk/(i+1));
@@ -487,11 +501,11 @@
int *indexes = calloc(topk, sizeof(int));
for(i = 0; i < m; ++i){
- int class = -1;
+ int class_id = -1;
char *path = paths[i];
for(j = 0; j < classes; ++j){
if(strstr(path, labels[j])){
- class = j;
+ class_id = j;
break;
}
}
@@ -509,9 +523,9 @@
free_image(crop);
top_k(pred, classes, topk, indexes);
- if(indexes[0] == class) avg_acc += 1;
+ if(indexes[0] == class_id) avg_acc += 1;
for(j = 0; j < topk; ++j){
- if(indexes[j] == class) avg_topk += 1;
+ if(indexes[j] == class_id) avg_topk += 1;
}
printf("%d: top 1: %f, top %d: %f\n", i, avg_acc/(i+1), topk, avg_topk/(i+1));
@@ -549,11 +563,11 @@
int *indexes = calloc(topk, sizeof(int));
for(i = 0; i < m; ++i){
- int class = -1;
+ int class_id = -1;
char *path = paths[i];
for(j = 0; j < classes; ++j){
if(strstr(path, labels[j])){
- class = j;
+ class_id = j;
break;
}
}
@@ -573,9 +587,9 @@
free_image(im);
top_k(pred, classes, topk, indexes);
free(pred);
- if(indexes[0] == class) avg_acc += 1;
+ if(indexes[0] == class_id) avg_acc += 1;
for(j = 0; j < topk; ++j){
- if(indexes[j] == class) avg_topk += 1;
+ if(indexes[j] == class_id) avg_topk += 1;
}
printf("%d: top 1: %f, top %d: %f\n", i, avg_acc/(i+1), topk, avg_topk/(i+1));
@@ -584,7 +598,7 @@
void try_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filename, int layer_num)
{
- network net = parse_network_cfg(cfgfile);
+ network net = parse_network_cfg_custom(cfgfile, 1);
if(weightfile){
load_weights(&net, weightfile);
}
@@ -665,7 +679,7 @@
void predict_classifier(char *datacfg, char *cfgfile, char *weightfile, char *filename, int top)
{
- network net = parse_network_cfg(cfgfile);
+ network net = parse_network_cfg_custom(cfgfile, 1);
if(weightfile){
load_weights(&net, weightfile);
}
@@ -696,8 +710,9 @@
strtok(input, "\n");
}
image im = load_image_color(input, 0, 0);
- image r = resize_min(im, size);
- resize_network(&net, r.w, r.h);
+ image r = letterbox_image(im, net.w, net.h);
+ //image r = resize_min(im, size);
+ //resize_network(&net, r.w, r.h);
printf("%d %d\n", r.w, r.h);
float *X = r.data;
@@ -847,11 +862,14 @@
srand(2222222);
CvCapture * cap;
- if(filename){
- cap = cvCaptureFromFile(filename);
- }else{
- cap = cvCaptureFromCAM(cam_index);
- }
+ if (filename) {
+ //cap = cvCaptureFromFile(filename);
+ cap = get_capture_video_stream(filename);
+ }
+ else {
+ //cap = cvCaptureFromCAM(cam_index);
+ cap = get_capture_webcam(cam_index);
+ }
int top = option_find_int(options, "top", 1);
@@ -873,7 +891,8 @@
struct timeval tval_before, tval_after, tval_result;
gettimeofday(&tval_before, NULL);
- image in = get_image_from_stream(cap);
+ //image in = get_image_from_stream(cap);
+ image in = get_image_from_stream_cpp(cap);
if(!in.data) break;
image in_s = resize_image(in, net.w, net.h);
@@ -979,11 +998,14 @@
srand(2222222);
CvCapture * cap;
- if(filename){
- cap = cvCaptureFromFile(filename);
- }else{
- cap = cvCaptureFromCAM(cam_index);
- }
+ if (filename) {
+ //cap = cvCaptureFromFile(filename);
+ cap = get_capture_video_stream(filename);
+ }
+ else {
+ //cap = cvCaptureFromCAM(cam_index);
+ cap = get_capture_webcam(cam_index);
+ }
int top = option_find_int(options, "top", 1);
@@ -1002,7 +1024,8 @@
struct timeval tval_before, tval_after, tval_result;
gettimeofday(&tval_before, NULL);
- image in = get_image_from_stream(cap);
+ //image in = get_image_from_stream(cap);
+ image in = get_image_from_stream_cpp(cap);
image in_s = resize_image(in, net.w, net.h);
show_image(in, "Threat Detection");
@@ -1046,7 +1069,7 @@
{
#ifdef OPENCV
printf("Classifier Demo\n");
- network net = parse_network_cfg(cfgfile);
+ network net = parse_network_cfg_custom(cfgfile, 1);
if(weightfile){
load_weights(&net, weightfile);
}
@@ -1057,9 +1080,11 @@
CvCapture * cap;
if(filename){
- cap = cvCaptureFromFile(filename);
+ //cap = cvCaptureFromFile(filename);
+ cap = get_capture_video_stream(filename);
}else{
- cap = cvCaptureFromCAM(cam_index);
+ //cap = cvCaptureFromCAM(cam_index);
+ cap = get_capture_webcam(cam_index);
}
int top = option_find_int(options, "top", 1);
@@ -1079,7 +1104,8 @@
struct timeval tval_before, tval_after, tval_result;
gettimeofday(&tval_before, NULL);
- image in = get_image_from_stream(cap);
+ //image in = get_image_from_stream(cap);
+ image in = get_image_from_stream_cpp(cap);
image in_s = resize_image(in, net.w, net.h);
show_image(in, "Classifier");
--
Gitblit v1.10.0