Old feature extraction method

This commit is contained in:
Joseph Redmon 2014-04-17 15:05:41 -07:00
parent b4b729a15e
commit ec16ee612f
3 changed files with 18 additions and 13 deletions

View File

@ -1,12 +1,12 @@
CC=gcc CC=gcc
COMMON=-Wall `pkg-config --cflags opencv` COMMON=-Wall `pkg-config --cflags opencv` -I/usr/local/cuda/include/
UNAME = $(shell uname) UNAME = $(shell uname)
OPTS=-O3 OPTS=-O3
ifeq ($(UNAME), Darwin) ifeq ($(UNAME), Darwin)
COMMON+= -isystem /usr/local/Cellar/opencv/2.4.6.1/include/opencv -isystem /usr/local/Cellar/opencv/2.4.6.1/include COMMON+= -isystem /usr/local/Cellar/opencv/2.4.6.1/include/opencv -isystem /usr/local/Cellar/opencv/2.4.6.1/include
LDFLAGS= -framework OpenCL LDFLAGS= -framework OpenCL
else else
OPTS+= -march=native -flto OPTS+= -march=native
LDFLAGS= -lOpenCL LDFLAGS= -lOpenCL
endif endif
CFLAGS= $(COMMON) $(OPTS) CFLAGS= $(COMMON) $(OPTS)

View File

@ -16,11 +16,13 @@ cl_info cl_init()
{ {
cl_info info; cl_info info;
info.initialized = 0; info.initialized = 0;
cl_uint platforms, devices; //cl_uint num_platforms, num_devices;
// Fetch the Platform and Device IDs; we only want one. // Fetch the Platform and Device IDs; we only want one.
info.error=clGetPlatformIDs(1, &info.platform, &platforms); cl_device_id devices[2];
info.error=clGetPlatformIDs(1, &info.platform, 0);
check_error(info); check_error(info);
info.error=clGetDeviceIDs(info.platform, CL_DEVICE_TYPE_ALL, 1, &info.device, &devices); info.error=clGetDeviceIDs(info.platform, CL_DEVICE_TYPE_ALL, 2, devices, 0);
info.device = devices[rand()%2];
check_error(info); check_error(info);
cl_context_properties properties[]={ cl_context_properties properties[]={

View File

@ -503,10 +503,11 @@ image features_output_size(network net, IplImage *src, int outh, int outw)
IplImage *sized = cvCreateImage(cvSize(w,h), src->depth, src->nChannels); IplImage *sized = cvCreateImage(cvSize(w,h), src->depth, src->nChannels);
cvResize(src, sized, CV_INTER_LINEAR); cvResize(src, sized, CV_INTER_LINEAR);
image im = ipl_to_image(sized); image im = ipl_to_image(sized);
normalize_array(im.data, im.h*im.w*im.c); //normalize_array(im.data, im.h*im.w*im.c);
//translate_image(im, -144);
resize_network(net, im.h, im.w, im.c); resize_network(net, im.h, im.w, im.c);
forward_network(net, im.data); forward_network(net, im.data);
image out = get_network_image_layer(net, 6); image out = get_network_image(net);
free_image(im); free_image(im);
cvReleaseImage(&sized); cvReleaseImage(&sized);
return copy_image(out); return copy_image(out);
@ -660,12 +661,11 @@ void visualize_cat()
cvWaitKey(0); cvWaitKey(0);
} }
void features_VOC_image(char *image_file, char *image_dir, char *out_dir) void features_VOC_image(char *image_file, char *image_dir, char *out_dir, int flip)
{ {
int flip = 1;
int interval = 4; int interval = 4;
int i,j; int i,j;
network net = parse_network_cfg("cfg/voc_imagenet.cfg"); network net = parse_network_cfg("cfg/voc_imagenet_nonorm.cfg");
char image_path[1024]; char image_path[1024];
sprintf(image_path, "%s/%s",image_dir, image_file); sprintf(image_path, "%s/%s",image_dir, image_file);
char out_path[1024]; char out_path[1024];
@ -714,7 +714,9 @@ void features_VOC_image(char *image_file, char *image_dir, char *out_dir)
fprintf(fp, "%d, %d, %d\n",out.c, out.h, out.w); fprintf(fp, "%d, %d, %d\n",out.c, out.h, out.w);
for(j = 0; j < out.c*out.h*out.w; ++j){ for(j = 0; j < out.c*out.h*out.w; ++j){
if(j != 0)fprintf(fp, ","); if(j != 0)fprintf(fp, ",");
fprintf(fp, "%g", out.data[j]); float o = out.data[j];
//if(o < 0) o = 0;
fprintf(fp, "%g", o);
} }
fprintf(fp, "\n"); fprintf(fp, "\n");
free_image(out); free_image(out);
@ -787,10 +789,11 @@ int main(int argc, char *argv[])
//test_vince(); //test_vince();
//test_full(); //test_full();
//train_VOC(); //train_VOC();
//features_VOC_image(argv[1], argv[2], argv[3]); features_VOC_image(argv[1], argv[2], argv[3], 0);
features_VOC_image(argv[1], argv[2], argv[3], 1);
//features_VOC_image_size(argv[1], atoi(argv[2]), atoi(argv[3])); //features_VOC_image_size(argv[1], atoi(argv[2]), atoi(argv[3]));
//visualize_imagenet_features("data/assira/train.list"); //visualize_imagenet_features("data/assira/train.list");
visualize_imagenet_topk("data/VOC2012.list"); //visualize_imagenet_topk("data/VOC2012.list");
//visualize_cat(); //visualize_cat();
//flip_network(); //flip_network();
//test_visualize(); //test_visualize();