keras-team / keras-applications

Reference implementations of popular deep learning models.
Other
2k stars 910 forks source link

High CPU utilization upon model.predict() #102

Open Terizian opened 5 years ago

Terizian commented 5 years ago

I have performed transfer learning using MobileNet and have exported the model to be used in a different applications for prediction.

img = Image.open(path)
img = img.resize((224,224))
img = np.array(img, dtype="float32")
x = img.reshape((1,) + img.shape)  # reshape image to 1x3x224x224
x = preprocess_input(x)
output = model.predict(x)

The code runs fine, but upon model.predict, my CPU utilization spikes up to 98%.

I'm currently using keras 2.2.4 within an Anaconda environment

taehoonlee commented 5 years ago

@Terizian, Could you describe the details such as statistics of 100 runs? The analysis for CPU and GPU utilizations needs to be more sophisticated.

Terizian commented 5 years ago

@Terizian, Could you describe the details such as statistics of 100 runs? The analysis for CPU and GPU utilizations needs to be more sophisticated.

@taehoonlee Thanks for your response. I would provide this information, but the system is offline so it's hard to pull out. I have a script that fetches images from a database, processes each image, then runs it through the model for prediction. I commented the code, then removed the comments section by section, while monitoring CPU utilization. It seems that it spikes only when I uncomment model.predict(). Does it use all the available system resources by default? I wanted to perform multiple predictions at once and I'm finding it impossible to do so when running just one instance does that to CPU utilization.