Run YOLO on AWS. ** I don't have much knowledge of AWS, so please see it as an example of a solution. ** **
[YOLO] https://github.com/ptxyasu/keras-yolo3 [AWS] EC2 https://aws.amazon.com/jp/ec2/
This time, I chose Ubuntu 16.04 AMI to match the development environment. The instance type is t2.micro, which is a free frame.
When I build the environment and try to clone keras-yolo3, an error occurs that there is no volume.
Change the volume size from 8GiB little by little. ** Note that you can only change it about once every 6 hours. However, be aware that the more you increase, the more you will be charged! !! ** ** As a result, it was increased to 20 GiB.
Even if I check the error text, I don't get much information.
I felt that one virtual CPU of t2.micro and 1GiB of memory were the problems. So I changed the instance type from t2.micro to t3a.2xlarge. Regarding this, it may have been good to change to t2.large or t2.xlarge. ** Please note that the price will be very high! ** **
If you read the error statement, the following is probably the problem. I think there is no font in AWS.
yolo_video.py
font = ImageFont.truetype(font='font/FiraMono-Medium.otf',
size=np.floor(8e-3 * image.size[1] + 0.5).astype('int32'))
This time, it is only necessary to obtain the class name and its coordinates instead of the detected image, so the part related to depiction can be deleted.
yolo_video.py
def detect_image(self, image):
start = timer()
if self.model_image_size != (None, None):
assert self.model_image_size[0]%32 == 0, 'Multiples of 32 required'
assert self.model_image_size[1]%32 == 0, 'Multiples of 32 required'
boxed_image = letterbox_image(image, tuple(reversed(self.model_image_size)))
else:
new_image_size = (image.width - (image.width % 32),
image.height - (image.height % 32))
boxed_image = letterbox_image(image, new_image_size)
image_data = np.array(boxed_image, dtype='float32')
print(image_data.shape)
image_data /= 255.
image_data = np.expand_dims(image_data, 0) # Add batch dimension.
out_boxes, out_scores, out_classes = self.sess.run(
[self.boxes, self.scores, self.classes],
feed_dict={
self.yolo_model.input: image_data,
self.input_image_shape: [image.size[1], image.size[0]],
K.learning_phase(): 0
})
print('Found {} boxes for {}'.format(len(out_boxes), 'img'))
for i, c in reversed(list(enumerate(out_classes))):
predicted_class = self.class_names[c]
box = out_boxes[i]
score = out_scores[i]
predicted_value = self.get_concentration(predicted_class)
value = max(value,predicted_value)
label = '{} {:.2f}'.format(predicted_class,score)
top, left, bottom, right = box
top = max(0, np.floor(top + 0.5).astype('int32'))
left = max(0, np.floor(left + 0.5).astype('int32'))
bottom = min(image.size[1], np.floor(bottom + 0.5).astype('int32'))
right = min(image.size[0], np.floor(right + 0.5).astype('int32'))
print(label, (left, top), (right, bottom))
if top - label_size[1] >= 0:
text_origin = np.array([left, top - label_size[1]])
else:
text_origin = np.array([left, top + 1])
# My kingdom for a good redistributable image drawing library.
end = timer()
print(end - start)
return image
def close_session(self):
self.sess.close()
By using the previous method, we were able to execute yolo. However, it becomes "Found 0 boxes for img" and the object is not recognized ...
A mistake in the learning model placed on the server? → There is no problem with the model Permission to open images and programs? → No change even if authority is given Development environment is multiple GPUs, AWS has multiple CPUs → It seems that it is not originally related, but it may have a slight effect (verification required)
It was executed, but no object was detected. The instance was deleted because the charge increased by about 5,000 yen due to the expansion of the volume and the change of the instance type.
We will work on it again after clarifying the cause of the failure and examining the optimal instance type. If you have any errors, please comment! Please.
Recommended Posts