General overview of the architecture of the service for assessing appearance based on neural networks



Introduction



Hello!



In this article I will share my experience in building a microservice architecture for a project using neural networks.



Let's talk about architecture requirements, look at various structural diagrams, analyze each of the components of the finished architecture, and evaluate the technical metrics of the solution.



Enjoy reading!



A few words about the problem and its solution



The main idea is to assess a person's attractiveness on a ten-point scale based on a photo.



In this article, we will move away from describing both the neural networks used and the process of data preparation and training. However, in one of the following publications, we will definitely return to the analysis of the assessment pipeline at an in-depth level.



Now we will go through the evaluation pipeline at the top level, and will focus on the interaction of microservices in the context of the overall project architecture. 



When working on the attractiveness assessment pipeline, the task was decomposed into the following components:



  1. Selecting faces in a photo
  2. Assessment of each person
  3. Render the result


MTCNN. PyTorch, backbone ResNet34 ā€“ Ā« / CPUĀ»









ML , , .





ML



ā€“ -, . :



  1. ā€“ ,
  2. ā€” Bottleneck
  3. - ā€”
  4. () ,
  5. , ,




, .



, , Telegram API.



, , .







, Single Responsibility .



Ā«attrai-telegram-botĀ»



Telegram API. 2 ā€“ . .



:



  1. , :

    • ,
  2. docker volume
  3. ā€œto_estimateā€ , , , , volume
  4. ā€“ , . ā€“ , .


, , celery worker, Ā«after_estimateĀ», , .



ā€œafter_estimateā€:



  1. ā€“ , ā€“
  2. ,


Ā«attrai-estimatorĀ»



celery worker , . ā€“ .



ā€œto_estimateā€:



  1. :

    1. (MTCNN)
    2. ( ResNet34)


      1. bounding boxes
  2. ()
  3. ā€œafter_estimateā€, ā€œattrai-telegram-botā€


Graylog (+ mongoDB + Elasticsearch)



Graylog ā€” . , .



, ELK , Python. , Graylog, GELFTCPHandler graypy root logger handlers python-.



, , ELK , , Graylog. , ā€“ Kibana - Graylog.



RabbitMQ



RabbitMQ ā€” AMQP.



Celery durable .



Redis



Redis ā€” NoSQL , Ā« ā€” Ā»



python- , - .



, Redis hashmap Ā«telegram_user_id => Ā», , , DoS-.





  1. Telegram
  2. Ā«attrai-telegram-botĀ» Telegram API
  3. Ā«to_estimateĀ»
  4. Ā«attrai-estimatorĀ» Ā«to_estimateĀ», Ā«after_estimateĀ»
  5. Ā«attrai-telegram-botĀ», Ā«after_estimateĀ»,


DevOps



, , ā€” DevOps



Docker Swarm



 





Docker Swarm  - , Docker Engine .



Ā«Ā», 2 ā€“ worker manager. (), , . .





leader manager worker



ā€“ 1 , leader manager worker. , .



, , production-, , , , ( , - - , ).



Docker Stack



Ā«Ā» ( docker services) docker stack



docker-compose , deploy .  



, ( N N , - , PyTorch`, )



attrai_estimator:
  image: 'erqups/attrai_estimator:1.2'
  deploy:
    replicas: 4
    resources:
      limits:
        cpus: '4'
    restart_policy:
      condition: on-failure
      ā€¦


, Redis, RabbitMQ Graylog ā€” stateful , Ā«attrai-estimatorĀ»,



ā€” Kubernetes?



, Kubernetes ā€“ , Docker Swarm, user friendly , .





VDS :



  • CPU: 4 IntelĀ® XeonĀ® Gold 5120 CPU @ 2.20GHz
  • RAM: 8 GB
  • SSD: 160 GB


, , , .



, , (, ), . CPU RAM .









, ,











, , ā€” . 



, , CPU, , .



I will add that initially the article was larger, but in order not to post a longread, I decided to omit some points in this article - we will return to them in future publications.



You can poke the bot in Telegram - @AttraiBot, it will work at least until the end of autumn 2020. Let me remind you - no user data is stored - neither the original images, nor the results of the evaluation pipeline - everything is demolished after processing.




All Articles