Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Machine Learning without PhD :)

Machine Learning without PhD :)

Байрам Аннаков @ MoscowPython Meetup 49

"Расскажем и покажем, как обучать машины и нейросети для решения простых и не очень задач классификации и распознавания".

Видео: http://www.moscowpython.ru/meetup/49/ml-no-phd/

Moscow Python Meetup
PRO

September 20, 2017
Tweet

More Decks by Moscow Python Meetup

Other Decks in Programming

Transcript

  1. Machine Learning
    without PHD
    App in the Air

    View Slide

  2. It all started
    with…

    View Slide

  3. How?
    Reproduce the same in Python
    Train your own model

    View Slide

  4. Reproduce

    View Slide

  5. ImageNet

    View Slide

  6. View Slide

  7. Recognize image
    from keras.applications.resnet50 import ResNet50
    from keras.preprocessing import image
    from keras.applications.resnet50 import
    preprocess_input, decode_predictions
    import numpy as np
    model = ResNet50(weights='imagenet')

    View Slide

  8. Recognize image
    img_path = 'elephant.jpg'
    img = image.load_img(img_path,
    target_size=(224, 224))
    x = image.img_to_array(img)
    x = np.expand_dims(x, axis=0)
    x = preprocess_input(x)

    View Slide

  9. Recognize image
    preds = model.predict(x)
    # decode the results into a list of tuples (class,
    description, probability)
    # (one such list for each sample in the batch)
    print('Predicted:',
    decode_predictions(preds, top=3)[0])
    # Predicted: [(u'n02504013', u'Indian_elephant',
    0.82658225), (u'n01871265', u'tusker', 0.1122357),
    (u'n02504458', u'African_elephant', 0.061040461)]

    View Slide

  10. CNN

    View Slide

  11. View Slide

  12. Train your own

    View Slide

  13. https:/
    /blog.keras.io/

    View Slide

  14. 72%

    View Slide

  15. VGG16

    View Slide

  16. +2 months —> 90%
    GPU!!
    Re-training more layers
    Different architecture
    Data augmentation
    Dropout

    View Slide

  17. 2 internal seminars

    View Slide

  18. Passport Scanner
    87%
    Rhythmic
    Gymnastics
    98,9%

    View Slide

  19. Rhythmic Gymnastics

    View Slide

  20. Approach
    • Collect data

    Simple iPhone app that helps draw and export
    • Prepare data

    Image = Grid. Each cell = 1 (black) or 0 (white)

    Convert Grid to Line

    Image = 000100011000011100011…
    • Train + Analyze

    Until satisfied with the score

    View Slide

  21. View Slide

  22. Prepare data
    import skimage

    import numpy

    View Slide

  23. Train and Analyze
    1. K-neighbors 78%
    from sklearn.neighbors import KNeighborsClassifier
    clf = KNeighborsClassifier(n_neighbors=1)
    clf.fit(x_train, y_train)
    clf.score(x_test, y_test)

    View Slide

  24. Train and Analyze
    2. K-neighbors + PCA 81%
    from sklearn.decomposition import PCA
    pca = PCA(n_components=40, whiten=True)
    pca.fit(x_train)
    x_train_pca = pca.transform(x_train)
    x_test_pca = pca.transform(x_test)
    //repeat KNN

    View Slide

  25. May be someone has
    already solved it?

    View Slide

  26. MNIST
    http://yann.lecun.com/exdb/mnist/

    View Slide

  27. 3. SVM 90%
    from sklearn import svm
    classifier = svm.SVC(gamma=0.001)
    classifier.fit(x_train, y_train)
    predicted = classifier.predict(x_test)

    View Slide

  28. Passport OCR
    Data
    char74
    icdar2003
    Architecture
    Modified MNIST

    View Slide

  29. http:/
    /course.fast.ai

    View Slide

  30. View Slide