mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
Added ability to use letter_box resizing in darknet.py sample
This commit is contained in:
@ -202,6 +202,10 @@ predict_image = lib.network_predict_image
|
|||||||
predict_image.argtypes = [c_void_p, IMAGE]
|
predict_image.argtypes = [c_void_p, IMAGE]
|
||||||
predict_image.restype = POINTER(c_float)
|
predict_image.restype = POINTER(c_float)
|
||||||
|
|
||||||
|
predict_image_letterbox = lib.network_predict_image_letterbox
|
||||||
|
predict_image_letterbox.argtypes = [c_void_p, IMAGE]
|
||||||
|
predict_image_letterbox.restype = POINTER(c_float)
|
||||||
|
|
||||||
def array_to_image(arr):
|
def array_to_image(arr):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
# need to return old values to avoid python freeing memory
|
# need to return old values to avoid python freeing memory
|
||||||
@ -251,9 +255,12 @@ def detect_image(net, meta, im, thresh=.5, hier_thresh=.5, nms=.45, debug= False
|
|||||||
pnum = pointer(num)
|
pnum = pointer(num)
|
||||||
if debug: print("Assigned pnum")
|
if debug: print("Assigned pnum")
|
||||||
predict_image(net, im)
|
predict_image(net, im)
|
||||||
|
letter_box = 0
|
||||||
|
#predict_image_letterbox(net, im)
|
||||||
|
#letter_box = 1
|
||||||
if debug: print("did prediction")
|
if debug: print("did prediction")
|
||||||
#dets = get_network_boxes(net, custom_image_bgr.shape[1], custom_image_bgr.shape[0], thresh, hier_thresh, None, 0, pnum, 0) # OpenCV
|
#dets = get_network_boxes(net, custom_image_bgr.shape[1], custom_image_bgr.shape[0], thresh, hier_thresh, None, 0, pnum, letter_box) # OpenCV
|
||||||
dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, None, 0, pnum, 0)
|
dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, None, 0, pnum, letter_box)
|
||||||
if debug: print("Got dets")
|
if debug: print("Got dets")
|
||||||
num = pnum[0]
|
num = pnum[0]
|
||||||
if debug: print("got zeroth index of pnum")
|
if debug: print("got zeroth index of pnum")
|
||||||
|
@ -4,7 +4,7 @@ rem C:\Python27\Scripts\pip install scikit-image
|
|||||||
rem C:\Python27\Scripts\pip install scipy
|
rem C:\Python27\Scripts\pip install scipy
|
||||||
rem C:\Python27\Scripts\pip install opencv-python
|
rem C:\Python27\Scripts\pip install opencv-python
|
||||||
|
|
||||||
C:\Python27\python.exe darknet.py
|
rem C:\Python27\python.exe darknet.py
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -14,6 +14,6 @@ rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\Scripts\pip install sci
|
|||||||
rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\Scripts\pip install scipy
|
rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\Scripts\pip install scipy
|
||||||
rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\Scripts\pip install opencv-python
|
rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\Scripts\pip install opencv-python
|
||||||
|
|
||||||
rem C:\Users\Alex\AppData\Local\Programs\Python\Python36\python.exe darknet.py
|
C:\Users\Alex\AppData\Local\Programs\Python\Python36\python.exe darknet.py
|
||||||
|
|
||||||
pause
|
pause
|
11
darknet.py
11
darknet.py
@ -202,6 +202,10 @@ predict_image = lib.network_predict_image
|
|||||||
predict_image.argtypes = [c_void_p, IMAGE]
|
predict_image.argtypes = [c_void_p, IMAGE]
|
||||||
predict_image.restype = POINTER(c_float)
|
predict_image.restype = POINTER(c_float)
|
||||||
|
|
||||||
|
predict_image_letterbox = lib.network_predict_image_letterbox
|
||||||
|
predict_image_letterbox.argtypes = [c_void_p, IMAGE]
|
||||||
|
predict_image_letterbox.restype = POINTER(c_float)
|
||||||
|
|
||||||
def array_to_image(arr):
|
def array_to_image(arr):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
# need to return old values to avoid python freeing memory
|
# need to return old values to avoid python freeing memory
|
||||||
@ -251,9 +255,12 @@ def detect_image(net, meta, im, thresh=.5, hier_thresh=.5, nms=.45, debug= False
|
|||||||
pnum = pointer(num)
|
pnum = pointer(num)
|
||||||
if debug: print("Assigned pnum")
|
if debug: print("Assigned pnum")
|
||||||
predict_image(net, im)
|
predict_image(net, im)
|
||||||
|
letter_box = 0
|
||||||
|
#predict_image_letterbox(net, im)
|
||||||
|
#letter_box = 1
|
||||||
if debug: print("did prediction")
|
if debug: print("did prediction")
|
||||||
#dets = get_network_boxes(net, custom_image_bgr.shape[1], custom_image_bgr.shape[0], thresh, hier_thresh, None, 0, pnum, 0) # OpenCV
|
#dets = get_network_boxes(net, custom_image_bgr.shape[1], custom_image_bgr.shape[0], thresh, hier_thresh, None, 0, pnum, letter_box) # OpenCV
|
||||||
dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, None, 0, pnum, 0)
|
dets = get_network_boxes(net, im.w, im.h, thresh, hier_thresh, None, 0, pnum, letter_box)
|
||||||
if debug: print("Got dets")
|
if debug: print("Got dets")
|
||||||
num = pnum[0]
|
num = pnum[0]
|
||||||
if debug: print("got zeroth index of pnum")
|
if debug: print("got zeroth index of pnum")
|
||||||
|
@ -833,6 +833,7 @@ LIB_API layer* get_network_layer(network* net, int i);
|
|||||||
LIB_API detection *make_network_boxes(network *net, float thresh, int *num);
|
LIB_API detection *make_network_boxes(network *net, float thresh, int *num);
|
||||||
LIB_API void reset_rnn(network *net);
|
LIB_API void reset_rnn(network *net);
|
||||||
LIB_API float *network_predict_image(network *net, image im);
|
LIB_API float *network_predict_image(network *net, image im);
|
||||||
|
LIB_API float *network_predict_image_letterbox(network *net, image im);
|
||||||
LIB_API float validate_detector_map(char *datacfg, char *cfgfile, char *weightfile, float thresh_calc_avg_iou, const float iou_thresh, const int map_points, int letter_box, network *existing_net);
|
LIB_API float validate_detector_map(char *datacfg, char *cfgfile, char *weightfile, float thresh_calc_avg_iou, const float iou_thresh, const int map_points, int letter_box, network *existing_net);
|
||||||
LIB_API void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int ngpus, int clear, int dont_show, int calc_map, int mjpeg_port, int show_imgs);
|
LIB_API void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int ngpus, int clear, int dont_show, int calc_map, int mjpeg_port, int show_imgs);
|
||||||
LIB_API void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filename, float thresh,
|
LIB_API void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filename, float thresh,
|
||||||
|
@ -842,6 +842,24 @@ float *network_predict_image(network *net, image im)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float *network_predict_image_letterbox(network *net, image im)
|
||||||
|
{
|
||||||
|
//image imr = letterbox_image(im, net->w, net->h);
|
||||||
|
float *p;
|
||||||
|
if (net->batch != 1) set_batch_network(net, 1);
|
||||||
|
if (im.w == net->w && im.h == net->h) {
|
||||||
|
// Input image is the same size as our net, predict on that image
|
||||||
|
p = network_predict(*net, im.data);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Need to resize image to the desired size for the net
|
||||||
|
image imr = letterbox_image(im, net->w, net->h);
|
||||||
|
p = network_predict(*net, imr.data);
|
||||||
|
free_image(imr);
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
int network_width(network *net) { return net->w; }
|
int network_width(network *net) { return net->w; }
|
||||||
int network_height(network *net) { return net->h; }
|
int network_height(network *net) { return net->h; }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user