Detectron2 使用 deepfashion2 數據集,訓練服飾偵測

deepfashion2 數據集位置與目錄

├── DeepFashion2
│   └── train
│       ├── annos
│       └── image

下載 Detectron2 環境

docker run --gpus all -d \
-it \
-e DISPLAY \
-e QT_X11_NO_MITSHM=1 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-v $HOME/.Xauthority:/root/.Xauthority \
-v /home/ubuntu/dataset/:/app/detectron2_repo/datasets/data \
--name Detectron2-deepfashion2 \
--restart=always \
--shm-size="1g" \
raidavid/detectron2:base

注意掛載目錄對應上面 deepfashion2 實際路徑

轉換為 COCO 格式 

使用 deepfashion2 提供的轉換工具 將格式轉換為 coco

from PIL import Image
import numpy as np
import json

dataset = {
    "info": {},
    "licenses": [],
    "images": [],
    "annotations": [],
    "categories": []
}

lst_name = ['short_sleeved_shirt', 'long_sleeved_shirt', 'short_sleeved_outwear', 'long_sleeved_outwear',
            'vest', 'sling', 'shorts', 'trousers', 'skirt', 'short_sleeved_dress',
            'long_sleeved_dress', 'vest_dress', 'sling_dress']

for idx, e  in enumerate(lst_name):
    dataset['categories'].append({
        'id': idx + 1,
        'name': e,
        'supercategory': "clothes",
        'keypoints': ['%i' % (i) for i in range(1, 295)],
        'skeleton': []
    })

num_images = 32153 #191961 
sub_index = 0  # the index of ground truth instance
for num in range(1, num_images + 1):
    json_name = '/app/detectron2_repo/datasets/data/DeepFashion2/train/annos/' + str(num).zfill(6) + '.json'
    image_name = '/app/detectron2_repo/datasets/data/DeepFashion2/train/image/' + str(num).zfill(6) + '.jpg'

    if (num >= 0):
        imag = Image.open(image_name)
        width, height = imag.size
        with open(json_name, 'r') as f:
            temp = json.loads(f.read())
            pair_id = temp['pair_id']

            dataset['images'].append({
                'coco_url': '',
                'date_captured': '',
                'file_name': str(num).zfill(6) + '.jpg',
                'flickr_url': '',
                'id': num,
                'license': 0,
                'width': width,
                'height': height
            })
            for i in temp:
                if i == 'source' or i == 'pair_id':
                    continue
                else:
                    points = np.zeros(294 * 3)
                    sub_index = sub_index + 1
                    box = temp[i]['bounding_box']
                    w = box[2] - box[0]
                    h = box[3] - box[1]
                    x_1 = box[0]
                    y_1 = box[1]
                    bbox = [x_1, y_1, w, h]
                    cat = temp[i]['category_id']
                    style = temp[i]['style']
                    seg = temp[i]['segmentation']
                    landmarks = temp[i]['landmarks']

                    points_x = landmarks[0::3]
                    points_y = landmarks[1::3]
                    points_v = landmarks[2::3]
                    points_x = np.array(points_x)
                    points_y = np.array(points_y)
                    points_v = np.array(points_v)
                    case = [0, 25, 58, 89, 128, 143, 158, 168, 182, 190, 219, 256, 275, 294]
                    idx_i, idx_j = case[cat - 1], case[cat]

                    for n in range(idx_i, idx_j):
                        points[3 * n] = points_x[n - idx_i]
                        points[3 * n + 1] = points_y[n - idx_i]
                        points[3 * n + 2] = points_v[n - idx_i]

                    num_points = len(np.where(points_v > 0)[0])

                    dataset['annotations'].append({
                        'area': w * h,
                        'bbox': bbox,
                        'category_id': cat,
                        'id': sub_index,
                        'pair_id': pair_id,
                        'image_id': num,
                        'iscrowd': 0,
                        'style': style,
                        'num_keypoints': num_points,
                        'keypoints': points.tolist(),
                        'segmentation': seg,
                    })


json_name = '/app/detectron2_repo/datasets/data/deepfashion2_validation.json'
with open(json_name, 'w') as f:
    json.dump(dataset, f)

訓練模型

建立 train.py

# Setup detectron2 logger
import detectron2
from detectron2.utils.logger import setup_logger
setup_logger()

# import some common libraries
import os
import numpy as np
import cv2
import random

# import some common detectron2 utilities
from detectron2 import model_zoo
from detectron2.engine import DefaultPredictor
from detectron2.engine import DefaultTrainer
from detectron2.config import get_cfg
from detectron2.utils.visualizer import Visualizer
from detectron2.data import MetadataCatalog
from detectron2.data.datasets import register_coco_instances
#register_coco_instances("deepfashion_train", {}, "/content/DeepFashion2/deepfashion2_train.json", "/content/DeepFashion2/train/image")
register_coco_instances("deepfashion_val", {}, "/app/detectron2_repo/datasets/data/deepfashion2_validation.json", "/app/detectron2_repo/datasets/data/DeepFashion2/train/image/")

cfg = get_cfg()

cfg.merge_from_file(model_zoo.get_config_file("COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml"))
cfg.DATASETS.TRAIN = ("deepfashion_val",)
cfg.DATASETS.TEST = ()
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml")  # Let training initialize from model zoo

cfg.SOLVER.IMS_PER_BATCH = 4
cfg.SOLVER.BASE_LR = 0.001
cfg.SOLVER.WARMUP_ITERS = 1000
cfg.SOLVER.MAX_ITER = 1500
# cfg.SOLVER.STEPS = (1000, 1500)
cfg.SOLVER.STEPS = []
cfg.SOLVER.GAMMA = 0.05
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 64
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 13

cfg.TEST.EVAL_PERIOD = 500
os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
trainer = DefaultTrainer(cfg) 
trainer.resume_or_load(resume=False)
trainer.train()

觀看訓練狀況

tensorboard --logdir output

在〈“Detectron2 使用 deepfashion2 數據集,訓練服飾偵測”〉中有 1 則留言

  1. Предлагаем услуги профессиональных инженеров офицальной мастерской.
    Еслли вы искали официальный сервисный центр xiaomi, можете посмотреть на сайте: сервисный центр xiaomi
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  2. Профессиональный сервисный центр по ремонту сетевых хранилищ в Москве.
    Мы предлагаем: ремонт сетевых хранилищ в москве
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  3. Профессиональный сервисный центр по ремонту фототехники в Москве.
    Мы предлагаем: ремонт вспышек
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
    Подробнее на сайте сервисного центра remont-vspyshek-realm.ru

  4. Even though depression is very common in women, most suicide cases are reported in men.
    People should shop online and enjoy the lowest can you drink on bactrim from responsible pharmacies online if you desire competitive
    A sigmoidoscopy, in which a lighted instrument called a sygmoidoscope is used to check for polyps and growths in the rectum and lower colon.

  5. Профессиональный сервисный центр по ремонту бытовой техники с выездом на дом.
    Мы предлагаем: сервис центры бытовой техники москва
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  6. Профессиональный сервисный центр по ремонту радиоуправляемых устройства – квадрокоптеры, дроны, беспилостники в том числе Apple iPad.
    Мы предлагаем: ремонт дронов
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  7. Профессиональный сервисный центр по ремонту радиоуправляемых устройства – квадрокоптеры, дроны, беспилостники в том числе Apple iPad.
    Мы предлагаем: ремонт дрона
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  8. Профессиональный сервисный центр по ремонту холодильников и морозильных камер.
    Мы предлагаем: мастерска по ремонту холодильников
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  9. Профессиональный сервисный центр по ремонту ноутбуков и компьютеров.дронов.
    Мы предлагаем:ремонт ноутбуков в москве рядом
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  10. The low testosterone accounts for the lack of development of male secondary sex characteristics.
    Forget about your medication problems with specialized how fast does keflex work at reduced prices
    You may provide MEDgle with comments concerning the MEDgle Content or MEDgle API or your evaluation and use thereof.

  11. Профессиональный сервисный центр по ремонту сотовых телефонов, смартфонов и мобильных устройств.
    Мы предлагаем: ремонт сотовых
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  12. If you have trouble asking questions after hearing about your diagnosis, the person you bring with you can ask them for you.
    Some fake websites claim to sell flagyl for bv is available online at the lowest possible medication price.
    A small number start in the milk sacs or lobules.

  13. There is no single ideal jurisdiction in the world for starting a business that would suit everyone. But there are countries whose legislative and tax system is ideally suited to your particular case.
    Very often we are approached by clients with the request “Quickly register a company in the EU and pay low taxes”. But during a consultation with a specialist it turns out that, for example, the client also wants to stay in the country of business for a longer period of time or permanently reside there with the possibility of obtaining EU citizenship, which means that it is necessary to additionally apply for a long-term residence permit abroad.
    In view of this situation, we always recommend approaching the choice of a country for starting a business comprehensively, taking into account both corporate, tax and immigration laws together with the goals and objectives that the entrepreneur wants to achieve.

  14. Regulated United Europe, musterilerden gelen surekli geri bildirimlere dayanarak ve cesitli Avrupa ulkelerindeki hukuki hizmetlere yonelik pazar ihtiyaclar?n? dikkate alarak performans?n? ve sunulan hizmetlerin duzeyini surekli olarak iyilestirmeye cal?smaktad?r. Musteri sorular?na/e-postalar?na yan?t suresi de minimumda tutulur.
    Fiyatland?rma alan?nda, Regulated United Europe, cogu hukuki hizmette sabit bir fiyat sunarak musterilerin ihtiyaclar?na uyum saglamaya cal?smaktad?r. Avrupa ulkeleri ag?rl?kl? olarak saatlik yasal ucretler uygulanmaktad?r.
    Muvekkillerimize proje uygulamalar?n?n her asamas?nda hukuki dan?smanl?k ve gunluk destek sagl?yoruz. Karmas?k cozumler, deneyimli avukatlardan olusan bir ekip taraf?ndan her muvekkil icin ayr? ayr? gelistirilmektedir.

  15. Профессиональный сервисный центр по ремонту сотовых телефонов, смартфонов и мобильных устройств.
    Мы предлагаем: ближайший ремонт сотовых
    Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!

  16. Offenheit fur Finanzinnovationen zu einer Drehscheibe fur bahnbrechende Geschaftsideen entwickelt. Wir sind bestrebt, die traditionellen Unternehmensgrenzen zu erweitern und unseren Kunden auf der ganzen Welt neue Start-up-Moglichkeiten zu bieten. Unser Ziel ist es, einen Mehrwert fur internationale Unternehmen zu schaffen, indem wir die grenzenlosen Moglichkeiten der Europaischen Union wahrend ihres technologischen Aufstiegs nutzen und nahtlose Geschaftsentscheidungen nur einen Klick entfernt ermoglichen.

    Effektivitat unserer Arbeit von den kollektiven Bemuhungen jedes einzelnen Teammitglieds abhangt. Unsere Vision basiert auf gegenseitiger Unterstutzung und taglicher Zusammenarbeit, angetrieben durch das Engagement mit Kunden, Partnern und Kollegen. Wir integrieren die Unternehmenswerte in jeden Aspekt unserer Arbeit und betonen, wie wichtig es ist, realistische Ziele zu setzen, die Verantwortung fur Entscheidungen im Team zu ubernehmen und Projekte bis zum Abschluss zu begleiten.

  17. The agreement allows for the exchange of information between other EU countries and Cyprus, even if the information is not required for tax purposes of these countries. However, the country from which the information is requested is not obliged to provide the information if it is a violation of the law or public interest of that country. It is also not allowed to request information that is not publicly available in that country.
    It should be noted that the Cypriot tax authorities in most cases do not have information on the beneficiaries of private companies or any other information material. For these reasons, Cypriot companies registered through nominees and information about the real owners is confidential.
    In this regard, persons whose information is withheld must be properly accumulated in the files of the registration agents. Professional secrecy cannot be used as an excuse for not providing information about these persons.
    However, the conditions under which professional secrecy may be lifted will depend on state law. Thus, disclosure will not be a simple automatic administrative procedure, but will require the intervention of local government officials.
    Opening a company in Cyprus can be a powerful step to expand your business and explore new markets. Because of its unique advantages, Cyprus offers great opportunities for growth and success in international business. However, success depends on careful planning, an understanding of the local business culture and effective resource management.

  18. Regulated United Europe s’efforce constamment d’ameliorer ses performances et le niveau de services fournis, sur la base des commentaires constants des clients et de la capture des besoins du marche en matiere de services juridiques dans divers pays europeens. Le temps de reponse aux demandes/e-mails des clients est egalement reduit au minimum.
    Dans le domaine de la tarification, Regulated United Europe essaie egalement de s’adapter aux besoins des clients en proposant un prix fixe pour la plupart des services juridiques fournis, malgre le fait que dans la plupart des pays europeens, des frais juridiques horaires sont principalement appliques.
    Nous apportons des conseils juridiques et un accompagnement quotidien a nos clients a chaque etape de la mise en ?uvre de leur projet. Des solutions complexes sont developpees par une equipe d’avocats experimentes individuellement pour chaque client.

  19. This may be partly due to the movements during sex which may push bacteria up into the bladder.
    View specials coming from first-rate pharmacies where you can lyrica 75 mg price on the grounds that it is economical and powerful
    Medically facilitated hemorrhage control study yields good results, more questions.

  20. Link pyramid, tier 1, tier 2, tier 3
    Tier 1 – 500 connections with positioning embedded in compositions on content domains

    Level 2 – 3000 domain Redirected hyperlinks

    Level 3 – 20000 references combination, comments, articles

    Employing a link hierarchy is useful for indexing systems.

    Necessitate:

    One link to the domain.

    Search Terms.

    Valid when 1 search term from the website title.

    Highlight the additional service!

    Essential! First-level references do not intersect with Tier 2 and Tier 3-rank links

    A link hierarchy is a tool for enhancing the circulation and inbound links of a digital property or virtual network