mirror of
https://github.com/pjreddie/darknet.git
synced 2023-08-10 21:13:14 +03:00
Fixed memory leaks for Yolo: train, test
This commit is contained in:
@ -89,9 +89,10 @@
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>C:\opencv_3.0\opencv\build\include;..\..\3rdparty\include;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir);$(cudnn)\include</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_CRTDBG_MAP_ALLOC;_MBCS;_TIMESPEC_DEFINED;_CRT_SECURE_NO_WARNINGS;_CRT_RAND_S;GPU;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<UndefinePreprocessorDefinitions>CUDNN;OPENCV;</UndefinePreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>CUDNN;_CRTDBG_MAP_ALLOC;_MBCS;_TIMESPEC_DEFINED;_CRT_SECURE_NO_WARNINGS;_CRT_RAND_S;GPU;WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<UndefinePreprocessorDefinitions>OPENCV;</UndefinePreprocessorDefinitions>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<ForcedIncludeFiles>stdlib.h;crtdbg.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -502,7 +502,7 @@ void resize_convolutional_layer(convolutional_layer *l, int w, int h)
|
||||
size_t total_byte;
|
||||
check_error(cudaMemGetInfo(&free_byte, &total_byte));
|
||||
if (l->workspace_size > free_byte || l->workspace_size >= total_byte / 2) {
|
||||
printf(" used slow CUDNN algo without Workspace! Need memory: %d, available: %d\n", l->workspace_size, (free_byte < total_byte/2) ? free_byte : total_byte/2);
|
||||
printf(" used slow CUDNN algo without Workspace! Need memory: %zu, available: %zu\n", l->workspace_size, (free_byte < total_byte/2) ? free_byte : total_byte/2);
|
||||
cudnn_convolutional_setup(l, cudnn_smallest);
|
||||
l->workspace_size = get_workspace_size(*l);
|
||||
}
|
||||
|
27
src/demo.c
27
src/demo.c
@ -312,6 +312,33 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int
|
||||
cvReleaseVideoWriter(&output_video_writer);
|
||||
printf("output_video_writer closed. \n");
|
||||
}
|
||||
|
||||
// free memory
|
||||
cvReleaseImage(&show_img);
|
||||
cvReleaseImage(&in_img);
|
||||
free_image(in_s);
|
||||
|
||||
free(avg);
|
||||
for (j = 0; j < FRAMES; ++j) free(predictions[j]);
|
||||
for (j = 0; j < FRAMES; ++j) free_image(images[j]);
|
||||
|
||||
for (j = 0; j < l.w*l.h*l.n; ++j) free(probs[j]);
|
||||
free(boxes);
|
||||
free(probs);
|
||||
|
||||
free_ptrs(names, net.layers[net.n - 1].classes);
|
||||
|
||||
int i;
|
||||
const int nsize = 8;
|
||||
for (j = 0; j < nsize; ++j) {
|
||||
for (i = 32; i < 127; ++i) {
|
||||
free_image(alphabet[j][i]);
|
||||
}
|
||||
free(alphabet[j]);
|
||||
}
|
||||
free(alphabet);
|
||||
|
||||
free_network(net);
|
||||
}
|
||||
#else
|
||||
void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int cam_index, const char *filename, char **names, int classes,
|
||||
|
@ -1,8 +1,3 @@
|
||||
#ifdef _DEBUG
|
||||
#include <stdlib.h>
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
|
||||
#include "network.h"
|
||||
#include "region_layer.h"
|
||||
#include "cost_layer.h"
|
||||
@ -221,8 +216,25 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i
|
||||
sprintf(buff, "%s/%s_final.weights", backup_directory, base);
|
||||
save_weights(net, buff);
|
||||
|
||||
//cvReleaseImage(&img);
|
||||
//cvDestroyAllWindows();
|
||||
#ifdef OPENCV
|
||||
cvReleaseImage(&img);
|
||||
cvDestroyAllWindows();
|
||||
#endif
|
||||
|
||||
// free memory
|
||||
pthread_join(load_thread, 0);
|
||||
free_data(buffer);
|
||||
|
||||
free(base);
|
||||
free(paths);
|
||||
free_list_contents(plist);
|
||||
free_list(plist);
|
||||
|
||||
free_list_contents_kvp(options);
|
||||
free_list(options);
|
||||
|
||||
free(nets);
|
||||
free_network(net);
|
||||
}
|
||||
|
||||
|
||||
@ -1150,6 +1162,7 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam
|
||||
|
||||
// free memory
|
||||
free_ptrs(names, net.layers[net.n - 1].classes);
|
||||
free_list_contents_kvp(options);
|
||||
free_list(options);
|
||||
|
||||
int i;
|
||||
@ -1236,6 +1249,9 @@ void run_detector(int argc, char **argv)
|
||||
if (filename[strlen(filename) - 1] == 0x0d) filename[strlen(filename) - 1] = 0;
|
||||
demo(cfg, weights, thresh, hier_thresh, cam_index, filename, names, classes, frame_skip, prefix, out_filename,
|
||||
http_stream_port, dont_show, ext_output);
|
||||
|
||||
free_list_contents_kvp(options);
|
||||
free_list(options);
|
||||
}
|
||||
else printf(" There isn't such command: %s", argv[2]);
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ void free_layer(layer l)
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
if (l.mask) free(l.mask);
|
||||
if (l.cweights) free(l.cweights);
|
||||
if (l.indexes) free(l.indexes);
|
||||
if (l.input_layers) free(l.input_layers);
|
||||
|
12
src/list.c
12
src/list.c
@ -1,6 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "list.h"
|
||||
#include "option_list.h"
|
||||
|
||||
list *make_list()
|
||||
{
|
||||
@ -79,6 +80,17 @@ void free_list_contents(list *l)
|
||||
}
|
||||
}
|
||||
|
||||
void free_list_contents_kvp(list *l)
|
||||
{
|
||||
node *n = l->front;
|
||||
while (n) {
|
||||
kvp *p = n->val;
|
||||
free(p->key);
|
||||
free(n->val);
|
||||
n = n->next;
|
||||
}
|
||||
}
|
||||
|
||||
void **list_to_array(list *l)
|
||||
{
|
||||
void **a = calloc(l->size, sizeof(void*));
|
||||
|
@ -22,5 +22,6 @@ void **list_to_array(list *l);
|
||||
|
||||
void free_list(list *l);
|
||||
void free_list_contents(list *l);
|
||||
void free_list_contents_kvp(list *l);
|
||||
|
||||
#endif
|
||||
|
@ -175,6 +175,7 @@ void find_replace(char *str, char *orig, char *rep, char *output)
|
||||
sprintf(buffer, "%s", str);
|
||||
if(!(p = strstr(buffer, orig))){ // Is 'orig' even in 'str'?
|
||||
sprintf(output, "%s", str);
|
||||
free(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -194,6 +195,7 @@ void find_replace_extension(char *str, char *orig, char *rep, char *output)
|
||||
int chars_from_end = strlen(buffer) - offset;
|
||||
if (!p || chars_from_end != strlen(orig)) { // Is 'orig' even in 'str' AND is 'orig' found at the end of 'str'?
|
||||
sprintf(output, "%s", str);
|
||||
free(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -206,13 +208,13 @@ void find_replace_extension(char *str, char *orig, char *rep, char *output)
|
||||
void replace_image_to_label(char *input_path, char *output_path) {
|
||||
//find_replace(input_path, "images", "labels", output_path); // COCO
|
||||
find_replace(input_path, "images/train2014/", "labels/train2014/", output_path); // COCO
|
||||
find_replace(input_path, "images/val2014/", "labels/val2014/", output_path); // COCO
|
||||
find_replace(output_path, "images/val2014/", "labels/val2014/", output_path); // COCO
|
||||
//find_replace(output_path, "JPEGImages", "labels", output_path); // PascalVOC
|
||||
find_replace(output_path, "VOC2007/JPEGImages", "VOC2007/labels", output_path); // PascalVOC
|
||||
find_replace(output_path, "VOC2012/JPEGImages", "VOC2012/labels", output_path); // PascalVOC
|
||||
// replace only ext of files
|
||||
find_replace_extension(output_path, ".jpg", ".txt", output_path);
|
||||
find_replace_extension(output_path, ".JPG", ".txt", output_path);
|
||||
find_replace_extension(output_path, ".JPG", ".txt", output_path); // error
|
||||
find_replace_extension(output_path, ".jpeg", ".txt", output_path);
|
||||
find_replace_extension(output_path, ".JPEG", ".txt", output_path);
|
||||
find_replace_extension(output_path, ".png", ".txt", output_path);
|
||||
@ -285,7 +287,7 @@ void strip(char *s)
|
||||
size_t offset = 0;
|
||||
for(i = 0; i < len; ++i){
|
||||
char c = s[i];
|
||||
if(c==' '||c=='\t'||c=='\n'||c =='\r') ++offset;
|
||||
if(c==' '||c=='\t'||c=='\n'||c =='\r'||c==0x0d||c==0x0a) ++offset;
|
||||
else s[i-offset] = c;
|
||||
}
|
||||
s[len-offset] = '\0';
|
||||
|
Reference in New Issue
Block a user