demo.py TOO SLOW
Hi @michalfaber ,
Thank you for your shared code. Recently I try to modify your demo code and use it in REAL TIME VIDEO. But the calculation after "output" spend too much times. It takes me about 0.5s per images. Would you give me some suggestions to improve the codes?
Hi @HoracceFeng I plan to write a C++ library which allows faster interpreting of model's output. Stay tuned.
This happens to me also. I tried to put an iterator but It is taking 8 seconds per image. I did it this way:
for input_image in imagelist:
tic = time.time()
params, model_params = config_reader()
canvas = process(input_image, params, model_params)
I tried first to put the config_reader() outside but it didn't work. I got canvas with the image but without any prediction. But when I put it inside it works. I think is related with the parallelization the GPU does. So the config_reader() just force it to run sequentially. But maybe I am doing it wrong, do you have any advices?
Hi, I want to make real-time application of this repo using web cam. but i can't optimize the speed performance (is about 2 seconds for single image inference). Has you @michalfaber finish example code for real time application with this repo ? and here is my code. in case, you can help me debug the code. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ import os import argparse import cv2 import math import time import numpy as np import util from config_reader import config_reader from scipy.ndimage.filters import gaussian_filter from model import get_testing_model from tools import infer from types import MappingProxyType
#set image path images_path='./sample_images' #list semua gambar file_list=os.listdir(images_path) #set model path keras_weights_file = 'model/keras/model.h5' model = get_testing_model() model.load_weights(keras_weights_file) #load config #params, model_params = config_reader() #params=MappingProxyType(params) #model_params = MappingProxyType(model_params) print('start processing...') for image in file_list: input_image = images_path+'/'+ image print(image) #load config #params = copy.deepcopy(real_params) #model_params = copy.deepcopy(real_model_params) params, model_params = config_reader() #generate image with body parts tic = time.time() canvas = infer(input_image, params, model_params, model) toc = time.time() print ('processing time is %.5f' % (toc - tic)) cv2.imwrite('./output/{}'.format(image),canvas) print('Done') +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ i'm really appreciate your response. thank you~.
Hi @albertchristianto , There is a couple of tricks I have tried to improve the performance.
- If you notice in the config file, there is this parameter for scale, If you actually find the right number, you maybe don't need to repeat the process for all the scales but for the one fits better for your application. That way the running time improves considerably.
- what is the size of your images? Maybe you could also try to resize them. There is a tradeoff however with accuracy, but you could try it and see how bad it is.
- The average is computed on the CPU, maybe you can try to compute it on the GPU by using Cuda mat.
- You can also try to fit the GPU with a batch of images, rather than one at a time.
Hope any of these help in your problem.
Please share if you find other ways to do it. :)
Hi @piperod ,
thank you very much for your response. I will try all your suggestion.
By the way, I have already use GPU to run the code. And I'm a little bit curious about the part of my code.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
for image in file_list:
input_image = images_path+'/'+ image
print(image)
#load config
#params = copy.deepcopy(real_params)
#model_params = copy.deepcopy(real_model_params)
params, model_params = config_reader()
#generate image with body parts
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
as you can see in that part of code, I load my config file for each iteration which isn't very efficient, but when I only load my config file once, the code only infer first image only. Based on your experience, is there any code in this repo that change the value of the parameter or Is this an example of bug in python because as you can see part of my code
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#params, model_params = config_reader()
#params=MappingProxyType(params)
#model_params = MappingProxyType(model_params)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I change the param list into read only list, but the problem is still occured.
I really appreciate your response again, because I am newbie in this field and feel desperate to debug this problem. Thank you very much.
Yes that still happens to me too. I think for some reason the model get flush from the GPU memory. But not really sure about it. It might be worthy to print the model to see if is still there on each iteration when you are reading the config params only once. You could also put them inside the code as constants that might help.
@piperod I have succeed debug it. I don't what is going on, but params['scale_search'] is always gone after we run process function. params['scale_search'] is a map object. Do you have any idea about this ? What is map object any way ? Right now I defined the scale search manually and I don't need to load the config file again. Thank you very much again to give me inspiration. haha. best regards, Albert
@piperod @albertchristianto Indeed, params['scale_search'] is a map object, and " x in params['scale_search'] " acts as a generator object, which is only useful in the first iteration.
Besides the solution above, you can also transfer params to a dict after using config_reader() and send the dict to the for loop. That also works.
@albertchristianto hi, could you please share the code how to do scale search manually? My code is also running too slowly.. Thank you!