Score Your Face Photo: a ML & Wechaty practice

本文介绍了一款基于Wechaty框架的自拍评分机器人应用开发过程。该应用利用深度学习技术对Instagram上带有#selfie标签的图片进行评分,并将其应用于微信聊天机器人中。

Recently I found a fun and easy middleware to use for WeChat, called Wechaty.

Wechaty can help developers quickly build applications based on Wechat, and it was born with a huge number of Potential users.

So I build a fun application based on Wechaty, called wechaty_selfie, which is a ChatBot that can score self-portraits.

selfie pear

Say goodbye to your choice of difficulty!

Screenshot of the application

selfie demo

Our development steps


Once you have a little nodejs knowledge, and a little deep learning basis, you can build it. :)

  1. Crawl data: The most important of this application is data. We crawled data(eg. picture URL, release time, the number of praise, the number of comments) with ‘selfie’ label from instagram.
  2. Filter data: In order to make the training data more convincing, we crawl the data with earlier release time. It is obviously that if a selfie has just been released, then it must not get enough exposure, so the number of comments and comments at this time is unstable. Considering this, we set the realease time threshold to 2000 seconds. We will filter out data which have realease time smaller than the threshold.
  3. Scoring strategy selection: We get the data(picture URL, the number of praise, the number of comments) for visual analysis, and found that most of the number of praise are between 0-10, so we simply consider the number of praise as the selfie’s score.
  4. Download pictures: We download the selfies that we will use by URL that we already have, and reshape them into 224 * 224 dimensions.
  5. Build DL model: In order to build the neural network quickly, we choose the pre-build model VGG16 in keras, and add five full connection layer on the top of it. The top of our model is a softMax layer with 10 categories.
  6. Build project & training model: Build wechaty project and the training of deep learning model.
  7. Debugging, success!

Appendix, packages we used

  • pylab: for drawing
  • matplotlib: for drawing
  • requests: handle http requests
  • numpy: matrix operations
  • h5py: formatting data sets
  • keras: deep learning
  • Wechaty: wechat middleware
  • Fs: transfer pictures

Some optimization recommendations

If you are interested what I have done and would like to Develop a similar application.

  • If you want to use pictures from Instagram that have the selfie label as the training data, you should crawl the pictures with earlier release time.
  • You may try several different scoring strategies.
  • You can build a more complex deep learning model.

Finally

I strongly recommend that you now click on the link below, there are surprises waiting for you!

And more details about my selfie bot, you can find in my github repository at: wechaty_selfie

Author: @huyingxi enjoying ML&Wechaty at BUPT

#include <iostream> #include <fstream> #include <vector> #include <string> class Student { private: std::string name; int id; double score; public: void setName(const std::string& n) { name = n; } void setId(int i) { id = i; } void setScore(double s) { score = s; } void display() const { std::cout << "Name: " << name << ", ID: " << id << ", Score: " << score << std::endl; } friend std::ostream& operator<<(std::ostream& os, const Student& student); friend std::istream& operator>>(std::istream& is, Student& student); }; std::ostream& operator<<(std::ostream& os, const Student& student) { os << student.name << " " << student.id << " " << student.score; return os; } std::istream& operator>>(std::istream& is, Student& student) { is >> student.name >> student.id >> student.score; return is; } void saveToFile(const std::vector<Student>& students, const std::string& filename) { std::ofstream file(filename); for (const auto& student : students) { file << student << "\n"; } file.close(); } void loadFromFile(std::vector<Student>& students, const std::string& filename) { std::ifstream file(filename); Student temp; while (file >> temp) { students.push_back(temp); } file.close(); } int main() { std::vector<Student> students; int choice; loadFromFile(students, "students.txt"); while (true) { std::cout << "\nMenu:\n"; std::cout << "1. Add Student\n"; std::cout << "2. Display Students\n"; std::cout << "3. Save and Exit\n"; std::cout << "Enter your choice: "; std::cin >> choice; if (choice == 1) { Student newStudent; std::cout << "Enter student name: "; std::string name; std::cin >> name; newStudent.setName(name); std::cout << "Enter student ID: "; int id; std::cin >> id; newStudent.setId(id); std::cout << "Enter student score: "; double score; std::cin >> score; newStudent.setScore(score); students.push_back(newStudent); } else if (choice == 2) { for (const auto& student : students) { student.display(); } } else if (choice == 3) { saveToFile(students, "students.txt"); break; } else { std::cout << "Invalid choice!" << std::endl; } } return 0; } 运行后具体输入什么
06-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值