Create your own dataset with aliens


    Segmentation of people using neural networks is no surprise. There are many applications, such as Sticky Ai , Teleport Live , Instagram , which allow you to perform such a complex task on a mobile phone in real-time.


    So, suppose planet Earth is confronted with extraterrestrial civilizations. And from aliens from the star system Alpha Centauri comes a request for the development of a new product. They really liked the Sticky Ai application , which allows you to cut people and make stickers, so they want to port the application to their intergalactic market.


    Unfortunately, our neural network, which is used in the segmentation application, is trained only on images of the human race, so it doesn't work well on aliens. There is an urgent need to expand our datas with aliens.


    Asking aliens for several thousand of their images, we proceed to the markup.


    Task:
    There are images of aliens, for each image it is necessary to create a black and white mask in which the alien will be highlighted with white and the background black.



    Solution:
    First of all, you need to make TK for freelancers who will mark the images. Since we need very high quality, we will mark the images in Photoshop.


    Spoiler

    If we do not need a very good quality, or the object to be selected is very simple, then such marking can be done with the help of broken lines (polygon vertices). This type of markup is available on Amazon Mechanical Turk and Yandeks.Toloki , where labor is very cheap.


    You can make the TOR in the form of a 10-page PDF document, but:


    1. Freelancers usually do not read the TK, and browse.
    2. The document is difficult to describe in detail the algorithm as to correctly and quickly need to mark.
    3. It takes a lot of time to write the document itself.

    Therefore, now we have completely abandoned TK in the form of a PDF document, and provide the task in the
    form of a training video. After this innovation:


    • The performance of freelancers has increased 2 times (since the video presents the fastest and best way to markup).
    • The questions asked by freelancers were reduced 3 times (as each step is shown on the video).
    • 2 times it turned out to reduce the cost of markup (since the price of an hour of work has not changed, but freelancers mark out twice as fast).

    Particular attention should be paid to the markup method in Photoshop. Photoshop is a very flexible program in which you can produce markup in different ways. Therefore, it is advisable to determine in advance what quality of markup you need, study different selection tools, compare them with each other and choose the one with which the image processing is the fastest.


    Example:
    There are two ways to select:
    Method A takes 5 minutes per image.
    Method B takes 10 minutes to image.


    With method A, in an hour, the freelancer marks out 12 images, so the price per image will be 150/12 = 12.5 rubles.
    With method B, the freelancer marks out 6 images per hour, so the price for the image will be 150/6 = 25 rubles.


    So, we found the best way to select and recorded a video instruction, what next?



    It remains to find freelancers. There are many freelance exchanges, such as Fl.ru , Weblancer , Freelans.ru .
    But lately we have been using the WORK-ZILLA freelance exchange because:


    1. There's pretty cheap labor.
    2. A lot of performers.
    3. Convenient interface for creating tasks.

    In order to create a task: We
    register, replenish the balance, click "Submit Task", select "Design" -> "Photo Processing".



    Fill in the title and description, determine the time to complete the task. Having processed several aliens, I noticed that on average one image takes 4 minutes. Those. 15 images are released per hour, so we set the price for one image 150/15 = 10 rubles.



    Immediately after the publication of the job performers begin to offer their services.



    We choose the most beautiful avatar experienced by reviews and approve as a performer, issue images. As you can see, the search for a freelancer took less than 15 minutes.



    The next morning, the performer sent the work.




    How to check it now?


    Of course, you can open each image in Photoshop and see how well everything is selected, but what to do if 20 people work for you at the same time, and each sends 40 images a day?


    Automate! To facilitate verification, I have implemented the following script on python:


    import cv2
    import numpy as np
    import os
    import shutil
    from __future__ import print_function
    from tqdm import tqdm_notebook as tqdm
    #функция, которая рисует фон как в фотошопеdefgenerate_checkerboard(shape, size):
        res = np.ones(shape, dtype=np.float32)
        for i in range(0, shape[0] // size + 1):
            for j in range(0, shape[1] // size + 1):
                if (i + j) % 2 == 0:
                    res[i * size:i * size + size, j * size:j * size + size] = 0.7return np.stack([res] * 3, axis=2)
    path = '01_Починок Сергей_13'
    files_im = filter(lambda x: x[-4:] == '.jpg', os.listdir(path  + '/images'))
    files_masks = filter(lambda x: x[-4:] == '.png', os.listdir(path  + '/masks'))
    print('Кол-во изображений: %s' % len(files_im))
    print('Кол-во масок: %s' % len(files_masks))
    if len(files_im) != len(files_masks):
        print('Кол-во изображений и масок не совпадает')
        raise Exception('bad count')   
    #создаем папку res, в которую будут записываться коллажи 
    os.makedirs(path + '/res')
    for idd in tqdm(map(lambda x: x[:-4], files_im)):
        print(idd)
        mask = cv2.imread(path + '/masks/' + idd + ".png") / 255.
        im = cv2.imread(path + '/images/' + idd + ".jpg")
        checkerboard = generate_checkerboard(im.shape[:2], 40) * 255
        cv2.imwrite(path + '/res/' + idd + ".jpg",
                    np.concatenate([im, im * (1 - mask), im * mask + (1 - mask) * checkerboard],axis=1))

    The script takes the original image, a mask, and makes a collage of them consisting of the original image, the cut out background and the cut out alien.


    Run the script and get these collages:











    After reviewing the images, we note that the artist singled out one image not very well.



    Please correct the image.



    After the freelancer has corrected all our comments, we confirm the work and write a grateful feedback to the freelancer.



    Bottom line:
    Suppose that in order to train a neural network, you will need 2000 alien images.
    Then, in order to collect such a dataset, you will need to spend only 2000 x 10 = 20,000 rubles, and if you consider that on average one freelancer processes 40 images per day and 10 people work on markup at the same time, then creating a dataset will take 2000 / (10 x 40) = 5 days.


    PS
    Of course, we have not yet encountered aliens, no one from the Prisma AI team is going to segment aliens, but with this example I wanted to show you how simple and cost-effective you can create your own datas for any task, be it to detect pedestrians for an unmanned vehicle or the definition of forests on satellite imagery.


    Also popular now: