TranslateProject/sources/tech/20201116 Day 5- drawing lots of faces with sketch-rnn.md
DarkSun f2d1d0491e 选题[tech]: 20201116 Day 5: drawing lots of faces with sketch-rnn
sources/tech/20201116 Day 5- drawing lots of faces with sketch-rnn.md
2020-11-18 05:04:25 +08:00

88 lines
4.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Day 5: drawing lots of faces with sketch-rnn)
[#]: via: (https://jvns.ca/blog/2020/11/16/day-5--lots-of-faces-with-sketch-rnn/)
[#]: author: (Julia Evans https://jvns.ca/)
Day 5: drawing lots of faces with sketch-rnn
======
Hello! This week its generative art week at RC, and I thought it would be fun to generate drawings of faces.
Someone suggested the [Google Quickdraw][1] dataset, which has a lot of pictures of faces. And even though I think most of the faces in there are not really that interesting, I really quite like some of them, like these two:
![][2] ![][3]
So that seems like somewhere to start!
### step 1: get the sketch-rnn model
sketch-rnn is an RNN trained on the quickdraw dataset that generates line drawings. You can see it in action in Monica Dinculescus very fun [magic sketchpad][4] demo here you start making a drawing, and itll complete you drawing as a cat / bridge / whatever you want.
I figured that would be a fun place to start, and [ml5js][5] has a [tutorial showing how to write Javascript code to draw things with sketch-rnn][6], which I followed.
### step 2: make the tutorial code use async/await
The ml5js example had a bunch of global variables and callbacks and I found it difficult to work with, so I spent a while refactoring it to use async/await so that I could play around with it more easily. This took a while but I got it to work.
### step 3: make sketch-rnn draw lots of faces and put them into a gallery
I started out with making a more interactive website, but decided to instead do something really simple to start: just get the model to draw a lot of faces and see how I felt about them.
Heres the resulting (very janky, not responsive) website I made, which draws faces and then puts them into a little “gallery” on the right: [lots of sketch-rnn faces][7]. You can see it “live” drawing the faces which is fun.
The set of images that comes out looks something like this:
![][8]
I dont really like _any_ of these faces, but its a start! Its also very slow on my 2015 laptop, but faster on the iPad. I didnt spend a lot of time profiling it, but it seems to spend a lot of time in some function with `lstm` in its name I dont know what an LSTM is exactly but I know its a component of an RNN, so I guess (as youd expect) it just has a lot of math to do in Javascript to calculate the next line to draw and thats slow.
### next step: maybe find out if sketch-rnn can tell the difference between “interesting” and “boring” faces
I think that this face:
![][2]
is a lot more interesting than this face:
![][9]
Can I convince the neural network to distinguish between faces that I think are interesting and boring and maybe only generate more “interesting” faces? Well see! Right now I am stuck on trying to get a pre-trained model loaded into Python, so theres a long way to go.
I did find someone whod done something kind of similar, on [bad flamingos vs good flamingos][10] in the quickdraw dataset.
I still dont really know anything about RNNs, but maybe if I can answer this question I will learn something about them.
### also theres a refrigerator poetry forum
Heres that refrigerator poetry forum I was talking about last week: <https://refrigerator-poetry-forum.herokuapp.com/>. You can write magnet poetry-style poems on a refrigerator. People wrote some charming poems and Im happy with it. I think I might use Rails for another project in the future.
Hopefully people wont abuse it, if theres abuse Ill just take it off the internet probably.
--------------------------------------------------------------------------------
via: https://jvns.ca/blog/2020/11/16/day-5--lots-of-faces-with-sketch-rnn/
作者:[Julia Evans][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://jvns.ca/
[b]: https://github.com/lujun9972
[1]: https://quickdraw.withgoogle.com/data/face
[2]: https://jvns.ca/images/face1.jpg
[3]: https://jvns.ca/images/face2.jpg
[4]: https://magic-sketchpad.glitch.me/
[5]: https://learn.ml5js.org
[6]: https://github.com/ml5js/ml5-library/tree/main/examples/javascript/SketchRNN/SketchRNN_interactive
[7]: https://lots-of-sketchrnn-faces.netlify.app/
[8]: https://jvns.ca/images/faces.png
[9]: https://jvns.ca/images/boring-face.png
[10]: https://colinmorris.github.io/blog/bad_flamingos