kookmin-sw / 2019-cap1-2019_4

Flex Ads to implement advertising system in offline market
MIT License
10 stars 7 forks source link

S3 upload, Rekognition 의 Latency 의 측정 및 문제점 분석 #56

Closed james-sungjae-lee closed 5 years ago

james-sungjae-lee commented 5 years ago

S3 를 업로드하고, Rekognition 을 분석하는 데 가장 많은 Latency 가 발생한다.

이러한 Latency 를 측정하기 위해 python 의 time 을 이용하여 face image 가 인식된 시점부터

분석 결과가 나타날 때 까지의 elapsed time 을 측정하였다.

기본적으로 시스템을 가동하고 첫 번째 인식 및 분석되는 사람의 경우 7 ~ 8 초 정도의 Latency 가 발생하며

그 이후로는 3.3 ~ 3.7 사이의 일정한 Latency 를 보이고 있다.

latency

더 빠른 시스템이 필요할 경우, face image 를 저화질로 변환하여 전송하는 등의 방법이 가능하다.

Latency 를 조정하거나, 관련한 문제가 생길 경우 본 이슈에 작성하도록 한다.

추가적으로 Chromedriver Get 까지의 Latency 도 측정할 필요가 있어 보인다.

james-sungjae-lee commented 5 years ago

더 빠른 인식 시스템을 위해, 먼저 IN_CREATE + time.sleep(1) 방식이 아닌 다른 Local File Detect 방식을 사용하도록 한다. 예를 들어, File Write 가 끝나는 지점을 인식할 수 있다.

james-sungjae-lee commented 5 years ago

관련 자료를를 찾아본 결과, IN_CLOSE_WRITE 를 사용해볼 수 있을 것 같다.

Screen Shot 2019-05-24 at 10 51 01 AM

변경 후 테스트하여 결과를 보도록 한다.

james-sungjae-lee commented 5 years ago

추가적으로, 이미지 resize 를 통한 network 전송량을 줄여 Latency 를 줄일 수도 있을 것 같다.

https://stackoverflow.com/questions/6685500/upload-resized-image-to-s3

해당 코드를 참고하여 테스트해 보도록 한다.

james-sungjae-lee commented 5 years ago

동일한 Network 환경에서 기본 이미지와 (100, 100) Resized 이미지로

S3 업로드 - Rekognition 분석 - 결과 반환에 걸리는 Latency 의 비교이다

Screen Shot 2019-05-27 at 5 58 39 PM Screen Shot 2019-05-27 at 5 59 37 PM

사용된 방법은 Local 환경에서 해당되는 이미지를 Resize 하여 새롭게 저장하고,

해당 파일을 다시 업로드 및 분석하는 것이다. detection 의 결과가 어느 정도로 정확한지 또한 분석할 필요가 있다

james-sungjae-lee commented 5 years ago
Screen Shot 2019-05-27 at 6 07 57 PM

(100 x 100) 이미지 또한 99.97042846679688 의 Similarity 를 보이므로, resizing 하는 것이 정확도에 문제를 주지는 않을 것으로 보인다.

james-sungjae-lee commented 5 years ago

원본 파일명 : now_filename 변경 파일명 : resize_filename

from PIL import Image

now_filename = 'test_jisoo.PNG' change_filename = now_filename[:-4] + '_resize.PNG' resize_ratio = 0.5

im = Image.open(now_filename) width, height = im.size print(width, height) resize_size = (width resize_ratio, height resize_ratio)

image = Image.open(now_filename) image.thumbnail(resize_size, Image.ANTIALIAS) image.save(change_filename, "PNG")

im = Image.open(change_filename) width, height = im.size print(width, height)

해당 코드를 image upload 전에 수정하여 넣으면 될 것으로 보인다.

james-sungjae-lee commented 5 years ago

IN_CLOSE_WRITE 와 Image 해상도 조정을 통해 1~2초 정도의 시간을 단축하였다.

평균적으로 2.2 ~ 2.5 초 정도의 반응 속도를 보이게 된다

Screenshot from 2019-05-30 11-30-21

이정도면 Latency 에 대한 보완은 완료된된 것으로 보고, 이슈를 닫는다.