1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617# π€ Interactive Machine Learning Experiments
> πΊπ¦ UKRAINE [IS BEING ATTACKED](https://war.ukraine.ua/) BY RUSSIAN ARMY. CIVILIANS ARE GETTING KILLED. RESIDENTIAL AREAS ARE GETTING BOMBED.
> - Help Ukraine via:
> - [Serhiy Prytula Charity Foundation](https://prytulafoundation.org/en/)
> - [Come Back Alive Charity Foundation](https://savelife.in.ua/en/donate-en/)
> - [National Bank of Ukraine](https://bank.gov.ua/en/news/all/natsionalniy-bank-vidkriv-spetsrahunok-dlya-zboru-koshtiv-na-potrebi-armiyi)
> - More info on [war.ukraine.ua](https://war.ukraine.ua/) and [MFA of Ukraine](https://twitter.com/MFA_Ukraine)
<hr/>
This is a collection of interactive machine-learning experiments. Each experiment consists of ποΈ Jupyter/Colab _notebook_ (to see how a model was trained) and π¨ _demo page_ (to see a model in action right in your browser).
- π¨ [Launch ML experiments demo](http://trekhleb.github.io/machine-learning-experiments/)
- ποΈ [Launch ML experiments Jupyter notebooks](https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/tree/master/experiments/)
> _You might also be interested in [Homemade GPT β’ JS](https://github.com/trekhleb/homemade-gpt-js)_
> β οΈ This repository contains machine learning **experiments** and **not** a production ready, reusable, optimised and fine-tuned code and models. This is rather a sandbox or a playground for learning and trying different machine learning approaches, algorithms and data-sets. Models might not perform well and there is a place for overfitting/underfitting.
## Experiments
Most of the models in these experiments were trained using [TensorFlow 2](https://www.tensorflow.org/) with [Keras](https://www.tensorflow.org/guide/keras/overview) support.
### Supervised Machine Learning
[Supervised learning](https://en.wikipedia.org/wiki/Supervised_learning) is when you have input variables `X` and an output variable `Y` and you use an algorithm to learn the mapping function from the input to the output: `Y = f(X)`. The goal is to approximate the mapping function so well that when you have new input data `X` that you can predict the output variables `Y` for that data. It is called supervised learning because the process of an algorithm learning from the training dataset can be thought of as a teacher supervising the learning process.
#### Multilayer Perceptron (MLP) or simple Neural Network (NN)
A [multilayer perceptron](https://en.wikipedia.org/wiki/Multilayer_perceptron) (MLP) is a class of feedforward artificial neural network (ANN). Multilayer perceptrons are sometimes referred to as "vanilla" neural networks (composed of multiple layers of perceptrons), especially when they have a single hidden layer. It can distinguish data that is not linearly separable.
<table>
<thead>
<tr>
<th align="left" width="150" style="width: 150px !important"> </th>
<th align="left" width="200" style="width: 200px !important">Experiment</th>
<th align="left" width="140" style="width: 140px !important">Model demo & training</th>
<th align="left">Tags</th>
<th align="left" width="140" style="width: 140px !important">Dataset</th>
</tr>
</thead>
<tbody>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/digits_recognition_mlp.png" alt="Handwritten digits recognition (MLP)" width="150" />
</td>
<td>
<a href="experiments/digits_recognition_mlp/digits_recognition_mlp.ipynb">
<b>Handwritten Digits Recognition (MLP)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/DigitsRecognitionMLP">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/digits_recognition_mlp/digits_recognition_mlp.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/digits_recognition_mlp/digits_recognition_mlp.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>MLP</code>
</td>
<td>
<a href="https://www.tensorflow.org/datasets/catalog/mnist">
MNIST
</a>
</td>
</tr>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/sketch_recognition_mlp.png" alt="Handwritten sketch recognition (MLP)" width="150" />
</td>
<td>
<a href="experiments/sketch_recognition_mlp/sketch_recognition_mlp.ipynb">
<b>Handwritten Sketch Recognition (MLP)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/SketchRecognitionMLP">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/sketch_recognition_mlp/sketch_recognition_mlp.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/sketch_recognition_mlp/sketch_recognition_mlp.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>MLP</code>
</td>
<td>
<a href="https://github.com/googlecreativelab/quickdraw-dataset">
QuickDraw
</a>
</td>
</tr>
</tbody>
</table>
#### Convolutional Neural Networks (CNN)
A [convolutional neural network](https://en.wikipedia.org/wiki/Convolutional_neural_network) (CNN, or ConvNet) is a class of deep neural networks, most commonly applied to analyzing visual imagery (photos, videos). They are used for detecting and classifying objects on photos and videos, style transfer, face recognition, pose estimation etc.
<table>
<thead>
<tr>
<th align="left" width="150" style="width: 150px !important"> </th>
<th align="left" width="200" style="width: 200px !important">Experiment</th>
<th align="left" width="140" style="width: 140px !important">Model demo & training</th>
<th align="left">Tags</th>
<th align="left" width="140" style="width: 140px !important">Dataset</th>
</tr>
</thead>
<tbody>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/digits_recognition_cnn.png" alt="Handwritten digits recognition (CNN)" />
</td>
<td>
<a href="experiments/digits_recognition_cnn/digits_recognition_cnn.ipynb">
<b>Handwritten Digits Recognition (CNN)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/DigitsRecognitionCNN">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/digits_recognition_cnn/digits_recognition_cnn.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/digits_recognition_cnn/digits_recognition_cnn.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>CNN</code>
</td>
<td>
<a href="https://www.tensorflow.org/datasets/catalog/mnist">
MNIST
</a>
</td>
</tr>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/sketch_recognition_cnn.png" alt="Handwritten sketch recognition (CNN)" width="150" />
</td>
<td>
<a href="experiments/sketch_recognition_cnn/sketch_recognition_cnn.ipynb">
<b>Handwritten Sketch Recognition (CNN)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/SketchRecognitionCNN">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/sketch_recognition_cnn/sketch_recognition_cnn.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/sketch_recognition_cnn/sketch_recognition_cnn.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>CNN</code>
</td>
<td>
<a href="https://github.com/googlecreativelab/quickdraw-dataset">
QuickDraw
</a>
</td>
</tr>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/rock_paper_scissors_cnn.jpg" alt="Rock Paper Scissors" width="150" />
</td>
<td>
<a href="experiments/rock_paper_scissors_cnn/rock_paper_scissors_cnn.ipynb">
<b>Rock Paper Scissors (CNN)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/RockPaperScissorsCNN">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/rock_paper_scissors_cnn/rock_paper_scissors_cnn.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/rock_paper_scissors_cnn/rock_paper_scissors_cnn.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>CNN</code>
</td>
<td>
<a href="http://www.laurencemoroney.com/rock-paper-scissors-dataset/">
RPS
</a>
</td>
</tr>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/rock_paper_scissors_mobilenet_v2.jpg" alt="Rock Paper Scissors" width="150" />
</td>
<td>
<a href="experiments/rock_paper_scissors_mobilenet_v2/rock_paper_scissors_mobilenet_v2.ipynb">
<b>Rock Paper Scissors (MobilenetV2)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/RockPaperScissorsMobilenetV2">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/rock_paper_scissors_mobilenet_v2/rock_paper_scissors_mobilenet_v2.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/rock_paper_scissors_mobilenet_v2/rock_paper_scissors_mobilenet_v2.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>MobileNetV2</code>,
<code>Transfer learning</code>,
<code>CNN</code>
</td>
<td>
<a href="http://www.laurencemoroney.com/rock-paper-scissors-dataset/">
RPS
</a>,
<a href="http://image-net.org/explore">
ImageNet
</a>
</td>
</tr>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/objects_detection_ssdlite_mobilenet_v2.jpg" alt="Objects detection" width="150" />
</td>
<td>
<a href="experiments/objects_detection_ssdlite_mobilenet_v2/objects_detection_ssdlite_mobilenet_v2.ipynb">
<b>Objects Detection (MobileNetV2)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/ObjectsDetectionSSDLiteMobilenetV2">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/objects_detection_ssdlite_mobilenet_v2/objects_detection_ssdlite_mobilenet_v2.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/objects_detection_ssdlite_mobilenet_v2/objects_detection_ssdlite_mobilenet_v2.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>MobileNetV2</code>,
<code>SSDLite</code>,
<code>CNN</code>
</td>
<td>
<a href="http://cocodataset.org/#home">
COCO
</a>
</td>
</tr>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/image_classification_mobilenet_v2.jpg" alt="Objects detection" width="150" />
</td>
<td>
<a href="experiments/image_classification_mobilenet_v2/image_classification_mobilenet_v2.ipynb">
<b>Image Classification (MobileNetV2)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/ImageClassificationMobilenetV2">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/image_classification_mobilenet_v2/image_classification_mobilenet_v2.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/image_classification_mobilenet_v2/image_classification_mobilenet_v2.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>MobileNetV2</code>,
<code>CNN</code>
</td>
<td>
<a href="http://image-net.org/explore">
ImageNet
</a>
</td>
</tr>
</tbody>
</table>
#### Recurrent Neural Networks (RNN)
A [recurrent neural network](https://en.wikipedia.org/wiki/Recurrent_neural_network) (RNN) is a class of deep neural networks, most commonly applied to sequence-based data like speech, voice, text or music. They are used for machine translation, speech recognition, voice synthesis etc.
<table>
<thead>
<tr>
<th align="left" width="150" style="width: 150px !important"> </th>
<th align="left" width="200" style="width: 200px !important">Experiment</th>
<th align="left" width="140" style="width: 140px !important">Model demo & training</th>
<th align="left">Tags</th>
<th align="left" width="140" style="width: 140px !important">Dataset</th>
</tr>
</thead>
<tbody>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/numbers_summation_rnn.png" alt="Numbers summation (RNN)" width="150" />
</td>
<td>
<a href="experiments/numbers_summation_rnn/numbers_summation_rnn.ipynb">
<b>Numbers Summation (RNN)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/NumbersSummationRNN">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/numbers_summation_rnn/numbers_summation_rnn.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/numbers_summation_rnn/numbers_summation_rnn.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>LSTM</code>,
<code>Sequence-to-sequence</code>
</td>
<td>
Auto-generated
</td>
</tr>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/text_generation_shakespeare_rnn.jpg" alt="Shakespeare Text Generation (RNN)" width="150" />
</td>
<td>
<a href="experiments/text_generation_shakespeare_rnn/text_generation_shakespeare_rnn.ipynb">
<b>Shakespeare Text Generation (RNN)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/TextGenerationShakespeareRNN">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/text_generation_shakespeare_rnn/text_generation_shakespeare_rnn.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/text_generation_shakespeare_rnn/text_generation_shakespeare_rnn.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>LSTM</code>,
<code>Character-based RNN</code>
</td>
<td>
<a href="https://storage.googleapis.com/download.tensorflow.org/data/shakespeare.txt">
Shakespeare
</a>
</td>
</tr>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/text_generation_wikipedia_rnn.png" alt="Wikipedia Text Generation (RNN)" width="150" />
</td>
<td>
<a href="experiments/text_generation_wikipedia_rnn/text_generation_wikipedia_rnn.ipynb">
<b>Wikipedia Text Generation (RNN)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/TextGenerationWikipediaRNN">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/text_generation_wikipedia_rnn/text_generation_wikipedia_rnn.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/text_generation_wikipedia_rnn/text_generation_wikipedia_rnn.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>LSTM</code>,
<code>Character-based RNN</code>
</td>
<td>
<a href="https://www.tensorflow.org/datasets/catalog/wikipedia">
Wikipedia
</a>
</td>
</tr>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/recipe_generation_rnn.jpg" alt="Recipe Generation (RNN)" width="150" />
</td>
<td>
<a href="experiments/recipe_generation_rnn/recipe_generation_rnn.ipynb">
<b>Recipe Generation (RNN)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/RecipeGenerationRNN">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/recipe_generation_rnn/recipe_generation_rnn.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/recipe_generation_rnn/recipe_generation_rnn.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>LSTM</code>,
<code>Character-based RNN</code>
</td>
<td>
<a href="https://eightportions.com/datasets/Recipes/">
Recipe box
</a>
</td>
</tr>
</tbody>
</table>
### Unsupervised Machine Learning
[Unsupervised learning](https://en.wikipedia.org/wiki/Unsupervised_learning) is when you only have input data `X` and no corresponding output variables. The goal for unsupervised learning is to model the underlying structure or distribution in the data in order to learn more about the data. These are called unsupervised learning because unlike supervised learning above there is no correct answers and there is no teacher. Algorithms are left to their own to discover and present the interesting structure in the data.
#### Generative Adversarial Networks (GANs)
A [generative adversarial network](https://en.wikipedia.org/wiki/Generative_adversarial_network) (GAN) is a class of machine learning frameworks where two neural networks contest with each other in a game. Two models are trained simultaneously by an adversarial process. For example a _generator_ ("the artist") learns to create images that look real, while a _discriminator_ ("the art critic") learns to tell real images apart from fakes.
<table>
<thead>
<tr>
<th align="left" width="150" style="width: 150px !important"> </th>
<th align="left" width="200" style="width: 200px !important">Experiment</th>
<th align="left" width="140" style="width: 140px !important">Model demo & training</th>
<th align="left">Tags</th>
<th align="left" width="140" style="width: 140px !important">Dataset</th>
</tr>
</thead>
<tbody>
<!-- Experiment -->
<tr>
<td>
<img src="demos/src/images/clothes_generation_dcgan.jpg" alt="Clothes Generation (DCGAN)" width="150" />
</td>
<td>
<a href="experiments/clothes_generation_dcgan/clothes_generation_dcgan.ipynb">
<b>Clothes Generation (DCGAN)</b>
</a>
</td>
<td>
<a href="https://trekhleb.github.io/machine-learning-experiments/#/experiments/ClothesGenerationDCGAN">
<img src="https://img.shields.io/static/v1?label=%F0%9F%8E%A8%20Launch&message=Demo&color=green" alt="Launch demo">
</a>
<a href="https://nbviewer.jupyter.org/github/trekhleb/machine-learning-experiments/blob/master/experiments/clothes_generation_dcgan/clothes_generation_dcgan.ipynb">
<img src="https://mybinder.org/badge_logo.svg" alt="Open in Binder"/>
</a>
<a href="https://colab.research.google.com/github/trekhleb/machine-learning-experiments/blob/master/experiments/clothes_generation_dcgan/clothes_generation_dcgan.ipynb">
<img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab"/>
</a>
</td>
<td>
<code>DCGAN</code>
</td>
<td>
<a href="https://www.tensorflow.org/datasets/catalog/fashion_mnist">
Fashion MNIST
</a>
</td>
</tr>
</tbody>
</table>
## How to use this repository locally
### Setup virtual environment for Experiments
```bash
# Create "experiments" environment (from the project root folder).
python3 -m venv .virtualenvs/experiments
# Activate environment.
source .virtualenvs/experiments/bin/activate
# or if you use Fish...
source .virtualenvs/experiments/bin/activate.fish
```
To quit an environment run `deactivate`.
### Install dependencies
```bash
# Upgrade pip and setuptools to the latest versions.
pip install --upgrade pip setuptools
# Install packages
pip install -r requirements.txt
```
To install new packages run `pip install package-name`. To add new packages to the requirements run `pip freeze > requirements.txt`.
### Launch Jupyter locally
In order to play around with Jupyter notebooks and see how models were trained you need to launch a [Jupyter Notebook](https://jupyter.org/) server.
```bash
# Launch Jupyter server.
jupyter notebook
```
Jupyter will be available locally at `http://localhost:8888/`. Notebooks with experiments may be found in `experiments` folder.
### Launch demos locally
Demo application is made on React by means of [create-react-app](https://github.com/facebook/create-react-app).
```bash
# Switch to demos folder from project root.
cd demos
# Install all dependencies.
yarn install
# Start demo server on http.
yarn start
# Or start demo server on https (for camera access in browser to work on localhost).
yarn start-https
```
Demos will be available locally at `http://localhost:3000/` or at `https://localhost:3000/`.
### Convert models
The `converter` environment is used to convert the models that were trained during the experiments from `.h5` Keras format to Javascript understandable formats (`tfjs_layers_model` or `tfjs_graph_model` formats with `.json` and `.bin` files) for further usage with [TensorFlow.js](https://www.tensorflow.org/js) in [Demo application](http://trekhleb.github.io/machine-learning-experiments/).
```bash
# Create "converter" environment (from the project root folder).
python3 -m venv .virtualenvs/converter
# Activate "converter" environment.
source .virtualenvs/converter/bin/activate
# or if you use Fish...
source .virtualenvs/converter/bin/activate.fish
# Install converter requirements.
pip install -r requirements.converter.txt
```
The conversion of `keras` models to `tfjs_layers_model`/`tfjs_graph_model` formats is done by [tfjs-converter](https://github.com/tensorflow/tfjs/tree/master/tfjs-converter):
For example:
```bash
tensorflowjs_converter --input_format keras \
./experiments/digits_recognition_mlp/digits_recognition_mlp.h5 \
./demos/public/models/digits_recognition_mlp
```
> β οΈ Converting the models to JS understandable formats and loading them to the browser directly might not be a good practice since in this case the user might need to load tens or hundreds of megabytes of data to the browser which is not efficient. Normally the model is being served from the back-end (i.e. [TensorFlow Extended](https://www.tensorflow.org/tfx)) and instead of loading it all to the browser the user will do a lightweight HTTP request to do a prediction. But since the [Demo App](http://trekhleb.github.io/machine-learning-experiments/) is just an experiment and not a production-ready app and for the sake of simplicity (to avoid having an up and running back-end) we're converting the models to JS understandable formats and loading them directly into the browser.
### Requirements
Recommended versions:
- Python: `> 3.7.3`.
- Node: `>= 12.4.0`.
- Yarn: `>= 1.13.0`.
In case if you have Python version `3.7.3` you might experience `RuntimeError: dictionary changed size during iteration` error when trying to `import tensorflow` (see the [issue](https://github.com/tensorflow/tensorflow/issues/33183)).
## You might also be interested in
- [Homemade Machine Learning](https://github.com/trekhleb/homemade-machine-learning/) - Python examples of popular machine learning algorithms with interactive Jupyter demos and math being explained.
- [NanoNeuron](https://github.com/trekhleb/nano-neuron) - 7 simple JavaScript functions that will give you a feeling of how machines can actually "learn".
- [Playground and Cheatsheet for Learning Python](https://github.com/trekhleb/learn-python) - Collection of Python scripts that are split by topics and contain code examples with explanations.
## Articles
- π [Story behind the project](https://github.com/trekhleb/machine-learning-experiments/blob/master/assets/story.en.md)
- π [Generating cooking recipes using TensorFlow and LSTM Recurrent Neural Network](https://github.com/trekhleb/machine-learning-experiments/blob/master/assets/recipes_generation.en.md) (a step-by-step guide)
## Author
- [@trekhleb](https://trekhleb.dev)