Label Studio的YOLO机器学习后端
Label Studio的YOLO机器学习后端旨在将先进的目标检测、分割、分类和视频目标跟踪功能直接集成到Label Studio中。
该集成功能让您能够利用强大的YOLOv8模型执行各类机器学习任务,大幅简化大规模数据集的标注流程,同时确保高质量的预测结果。
支持的功能
| YOLO任务名称 | LS控制标签 | 支持预测 | 支持LS导入 | 支持LS导出 |
|---|---|---|---|---|
| Object Detection | <RectangleLabels> |
✅ | YOLO, COCO | YOLO, COCO |
| Oriented Bounding Boxes (OBB) | <RectangleLabels model_obb="true"> |
✅ | YOLO | YOLO |
| Image Instance Segmentation: Polygons | <PolygonLabels> |
✅ | COCO | YOLO, COCO |
| Image Semantic Segmentation: Masks | <BrushLabels> |
❌ | Native | Native |
| Image Classification | <Choices> |
✅ | Native | Native |
| Pose Detection | <KeyPoints> |
✅ | Native | Native |
| Video Object Tracking | <VideoRectangle> |
✅ | Native | Native |
| Video Temporal Classification | <TimelineLabels> |
✅ | Native | Native |
- LS Control Tag: Label Studio 的control tag标注配置项。
- 支持LS导入: 表示Label Studio是否支持从YOLO格式导入到Label Studio(使用LS转换器)。
- 支持LS导出: 表示Label Studio是否支持从Label Studio导出为YOLO格式(数据管理器上的导出按钮以及使用LS转换器)。
- 原生: 原生意味着仅支持Label Studio的原生JSON格式。
开始之前
在开始之前,您需要安装Label Studio ML后端。
本教程使用YOLO示例。
快速入门
在
docker-compose.yml文件中添加LABEL_STUDIO_URL和LABEL_STUDIO_API_KEY。 这些变量应分别指向您的Label Studio实例及其API密钥。 有关如何查找Label Studio API密钥的更多信息,请参阅我们的文档。运行docker compose
docker-compose up --build打开Label Studio并创建一个新项目,使用以下标注配置:
<View> <Image name="image" value="$image"/> <RectangleLabels name="label" toName="image" model_score_threshold="0.25"> <Label value="Car" background="blue" predicted_values="jeep,cab,limousine,truck"/> RectangleLabels> View>然后在项目设置的模型页面中,连接模型。默认URL为
http://localhost:9090。将图像或视频(根据您要解决的任务类型)添加到Label Studio。
在数据管理器中打开任意任务,查看YOLO模型的预测结果。
标注配置
支持的对象与控制标签
对象标签
控制标签
- 分类; 图像分类任务- Bounding boxes;目标检测任务- Polygons; 多边形标注任务- 视频边界框; 视频对象追踪任务- 关键点;姿态检测任务- 视频时间轴标签;针对视频的多标签时间分类任务
如何跳过控制标签?
如果您不想在某些控制标签中使用ML后端,可以通过在控制标签中添加model_skip="true"属性来强制跳过:
<Choices name="choice" toName="image" model_skip="true">
混合对象与控制标签
您可以在一个项目中混合使用不同的对象和控制标签。 YOLO模型将检测所有已知的控制标签并为其生成预测。 例如:
<View>
<Image name="image1" value="$image"/>
<RectangleLabels name="label" toName="image1" model_score_threshold="0.1">
<Label value="person" background="red"/>
<Label value="car" background="blue"/>
</RectangleLabels>
<Image name="image2" value="$image"/>
<Choices name="choice" toName="image2" model_score_threshold="0.1">
<Choice value="airship"/>
<Choice value="passenger_car"/>
</Choices>
</View>
在这个示例中,RectangleLabels和Choices都将被YOLO模型检测和预测。
您还可以在同一任务中使用不同的YOLO模型进行视觉比较:
<View>
<Image name="image1" value="$image"/>
<RectangleLabels name="label1" toName="image1" model_path="yolov8n.pt" model_score_threshold="0.1">
<Label value="car" background="blue"/>
</RectangleLabels>
<RectangleLabels name="label2" toName="image1" model_path="yolov8m.pt" model_score_threshold="0.1">
<Label value="car" background="red"/>
</RectangleLabels>
</View>
标签与选项映射
graph TD
A[Label Studio :: Labeling Config :: Labels or Choices] <--> B[ML Model :: Names]
如果使用常见的YOLO模型,您需要添加标签与机器学习模型标签之间的映射关系。
默认情况下,YOLO机器学习后端会使用您在value属性中指定的相同(或小写)名称。
在这个示例中,标签"Jeep"将被映射到ML模型中的"jeep":
<Choice value="Jeep"/>
如需更精确的控制,您可以使用predicted_values属性来指定来自机器学习模型的多个不同标签:
<Choice value="Car" predicted_values="jeep,cab,limousine"/>
Tip: How to find all YOLO model names?
Labels are printed in the ML model logs when you start using the ML backend with the INFO logging level.
或者您可以在YOLO_CLASSES.md中找到一些标签
Tip: How to map my labels to YOLO names using an LLM?
You can use an LLM model (e.g. ChatGPT) to automatically build mapping between Label Studio labels and ML model labels. Here is an example of a prompt for this. It includes 1000 labels from YOLOv8 classification model (`yolov8n-cls`).
**Task:**
1. **ML Model Labels:**
- I have the following labels in my ML model:
['tench', 'goldfish', 'great_white_shark', 'tiger_shark', 'hammerhead', 'electric_ray', 'stingray', 'cock', 'hen', 'ostrich', 'brambling', 'goldfinch', 'house_finch', 'junco', 'indigo_bunting', 'robin', 'bulbul', 'jay', 'magpie', 'chickadee', 'water_ouzel', 'kite', 'bald_eagle', 'vulture', 'great_grey_owl', 'European_fire_salamander', 'common_newt', 'eft', 'spotted_salamander', 'axolotl', 'bullfrog', 'tree_frog', 'tailed_frog', 'loggerhead', 'leatherback_turtle', 'mud_turtle', 'terrapin', 'box_turtle', 'banded_gecko', 'common_iguana', 'American_chameleon', 'whiptail', 'agama', 'frilled_lizard', 'alligator_lizard', 'Gila_monster', 'green_lizard', 'African_chameleon', 'Komodo_dragon', 'African_crocodile', 'American_alligator', 'triceratops', 'thunder_snake', 'ringneck_snake', 'hognose_snake', 'green_snake', 'king_snake', 'garter_snake', 'water_snake', 'vine_snake', 'night_snake', 'boa_constrictor', 'rock_python', 'Indian_cobra', 'green_mamba', 'sea_snake', 'horned_viper', 'diamondback', 'sidewinder', 'trilobite', 'harvestman', 'scorpion', 'black_and_gold_garden_spider', 'barn_spider', 'garden_spider', 'black_widow', 'tarantula', 'wolf_spider', 'tick', 'centipede', 'black_grouse', 'ptarmigan', 'ruffed_grouse', 'prairie_chicken', 'peacock', 'quail', 'partridge', 'African_grey', 'macaw', 'sulphur-crested_cockatoo', 'lorikeet', 'coucal', 'bee_eater', 'hornbill', 'hummingbird', 'jacamar', 'toucan', 'drake', 'red-breasted_merganser', 'goose', 'black_swan', 'tusker', 'echidna', 'platypus', 'wallaby', 'koala', 'wombat', 'jellyfish', 'sea_anemone', 'brain_coral', 'flatworm', 'nematode', 'conch', 'snail', 'slug', 'sea_slug', 'chiton', 'chambered_nautilus', 'Dungeness_crab', 'rock_crab', 'fiddler_crab', 'king_crab', 'American_lobster', 'spiny_lobster', 'crayfish', 'hermit_crab', 'isopod', 'white_stork', 'black_stork', 'spoonbill', 'flamingo', 'little_blue_heron', 'American_egret', 'bittern', 'crane_(bird)', 'limpkin', 'European_gallinule', 'American_coot', 'bustard', 'ruddy_turnstone', 'red-backed_sandpiper', 'redshank', 'dowitcher', 'oystercatcher', 'pelican', 'king_penguin', 'albatross', 'grey_whale', 'killer_whale', 'dugong', 'sea_lion', 'Chihuahua', 'Japanese_spaniel', 'Maltese_dog', 'Pekinese', 'Shih-Tzu', 'Blenheim_spaniel', 'papillon', 'toy_terrier', 'Rhodesian_ridgeback', 'Afghan_hound', 'basset', 'beagle', 'bloodhound', 'bluetick', 'black-and-tan_coonhound', 'Walker_hound', 'English_foxhound', 'redbone', 'borzoi', 'Irish_wolfhound', 'Italian_greyhound', 'whippet', 'Ibizan_hound', 'Norwegian_elkhound', 'otterhound', 'Saluki', 'Scottish_deerhound', 'Weimaraner', 'Staffordshire_bullterrier', 'American_Staffordshire_terrier', 'Bedlington_terrier', 'Border_terrier', 'Kerry_blue_terrier', 'Irish_terrier', 'Norfolk_terrier', 'Norwich_terrier', 'Yorkshire_terrier', 'wire-haired_fox_terrier', 'Lakeland_terrier', 'Sealyham_terrier', 'Airedale', 'cairn', 'Australian_terrier', 'Dandie_Dinmont', 'Boston_bull', 'miniature_schnauzer', 'giant_schnauzer', 'standard_schnauzer', 'Scotch_terrier', 'Tibetan_terrier', 'silky_terrier', 'soft-coated_wheaten_terrier', 'West_Highland_white_terrier', 'Lhasa', 'flat-coated_retriever', 'curly-coated_retriever', 'golden_retriever', 'Labrador_retriever', 'Chesapeake_Bay_retriever', 'German_short-haired_pointer', 'vizsla', 'English_setter', 'Irish_setter', 'Gordon_setter', 'Brittany_spaniel', 'clumber', 'English_springer', 'Welsh_springer_spaniel', 'cocker_spaniel', 'Sussex_spaniel', 'Irish_water_spaniel', 'kuvasz', 'schipperke', 'groenendael', 'malinois', 'briard', 'kelpie', 'komondor', 'Old_English_sheepdog', 'Shetland_sheepdog', 'collie', 'Border_collie', 'Bouvier_des_Flandres', 'Rottweiler', 'German_shepherd', 'Doberman', 'miniature_pinscher', 'Greater_Swiss_Mountain_dog', 'Bernese_mountain_dog', 'Appenzeller', 'EntleBucher', 'boxer', 'bull_mastiff', 'Tibetan_mastiff', 'French_bulldog', 'Great_Dane', 'Saint_Bernard', 'Eskimo_dog', 'malamute', 'Siberian_husky', 'dalmatian', 'affenpinscher', 'basenji', 'pug', 'Leonberg', 'Newfoundland', 'Great_Pyrenees', 'Samoyed', 'Pomeranian', 'chow', 'keeshond', 'Brabancon_griffon', 'Pembroke', 'Cardigan', 'toy_poodle', 'miniature_poodle', 'standard_poodle', 'Mexican_hairless', 'timber_wolf', 'white_wolf', 'red_wolf', 'coyote', 'dingo', 'dhole', 'African_hunting_dog', 'hyena', 'red_fox', 'kit_fox', 'Arctic_fox', 'grey_fox', 'tabby', 'tiger_cat', 'Persian_cat', 'Siamese_cat', 'Egyptian_cat', 'cougar', 'lynx', 'leopard', 'snow_leopard', 'jaguar', 'lion', 'tiger', 'cheetah', 'brown_bear', 'American_black_bear', 'ice_bear', 'sloth_bear', 'mongoose', 'meerkat', 'tiger_beetle', 'ladybug', 'ground_beetle', 'long-horned_beetle', 'leaf_beetle', 'dung_beetle', 'rhinoceros_beetle', 'weevil', 'fly', 'bee', 'ant', 'grasshopper', 'cricket', 'walking_stick', 'cockroach', 'mantis', 'cicada', 'leafhopper', 'lacewing', 'dragonfly', 'damselfly', 'admiral', 'ringlet', 'monarch', 'cabbage_butterfly', 'sulphur_butterfly', 'lycaenid', 'starfish', 'sea_urchin', 'sea_cucumber', 'wood_rabbit', 'hare', 'Angora', 'hamster', 'porcupine', 'fox_squirrel', 'marmot', 'beaver', 'guinea_pig', 'sorrel', 'zebra', 'hog', 'wild_boar', 'warthog', 'hippopotamus', 'ox', 'water_buffalo', 'bison', 'ram', 'bighorn', 'ibex', 'hartebeest', 'impala', 'gazelle', 'Arabian_camel', 'llama', 'weasel', 'mink', 'polecat', 'black-footed_ferret', 'otter', 'skunk', 'badger', 'armadillo', 'three-toed_sloth', 'orangutan', 'gorilla', 'chimpanzee', 'gibbon', 'siamang', 'guenon', 'patas', 'baboon', 'macaque', 'langur', 'colobus', 'proboscis_monkey', 'marmoset', 'capuchin', 'howler_monkey', 'titi', 'spider_monkey', 'squirrel_monkey', 'Madagascar_cat', 'indri', 'Indian_elephant', 'African_elephant', 'lesser_panda', 'giant_panda', 'barracouta', 'eel', 'coho', 'rock_beauty', 'anemone_fish', 'sturgeon', 'gar', 'lionfish', 'puffer', 'abacus', 'abaya', 'academic_gown', 'accordion', 'acoustic_guitar', 'aircraft_carrier', 'airliner', 'airship', 'altar', 'ambulance', 'amphibian', 'analog_clock', 'apiary', 'apron', 'ashcan', 'assault_rifle', 'backpack', 'bakery', 'balance_beam', 'balloon', 'ballpoint', 'Band_Aid', 'banjo', 'bannister', 'barbell', 'barber_chair', 'barbershop', 'barn', 'barometer', 'barrel', 'barrow', 'baseball', 'basketball', 'bassinet', 'bassoon', 'bathing_cap', 'bath_towel', 'bathtub', 'beach_wagon', 'beacon', 'beaker', 'bearskin', 'beer_bottle', 'beer_glass', 'bell_cote', 'bib', 'bicycle-built-for-two', 'bikini', 'binder', 'binoculars', 'birdhouse', 'boathouse', 'bobsled', 'bolo_tie', 'bonnet', 'bookcase', 'bookshop', 'bottlecap', 'bow', 'bow_tie', 'brass', 'brassiere', 'breakwater', 'breastplate', 'broom', 'bucket', 'buckle', 'bulletproof_vest', 'bullet_train', 'butcher_shop', 'cab', 'caldron', 'candle', 'cannon', 'canoe', 'can_opener', 'cardigan', 'car_mirror', 'carousel', "carpenter's_kit", 'carton', 'car_wheel', 'cash_machine', 'cassette', 'cassette_player', 'castle', 'catamaran', 'CD_player', 'cello', 'cellular_telephone', 'chain', 'chainlink_fence', 'chain_mail', 'chain_saw', 'chest', 'chiffonier', 'chime', 'china_cabinet', 'Christmas_stocking', 'church', 'cinema', 'cleaver', 'cliff_dwelling', 'cloak', 'clog', 'cocktail_shaker', 'coffee_mug', 'coffeepot', 'coil', 'combination_lock', 'computer_keyboard', 'confectionery', 'container_ship', 'convertible', 'corkscrew', 'cornet', 'cowboy_boot', 'cowboy_hat', 'cradle', 'crane_(machine)', 'crash_helmet', 'crate', 'crib', 'Crock_Pot', 'croquet_ball', 'crutch', 'cuirass', 'dam', 'desk', 'desktop_computer', 'dial_telephone', 'diaper', 'digital_clock', 'digital_watch', 'dining_table', 'dishrag', 'dishwasher', 'disk_brake', 'dock', 'dogsled', 'dome', 'doormat', 'drilling_platform', 'drum', 'drumstick', 'dumbbell', 'Dutch_oven', 'electric_fan', 'electric_guitar', 'electric_locomotive', 'entertainment_center', 'envelope', 'espresso_maker', 'face_powder', 'feather_boa', 'file', 'fireboat', 'fire_engine', 'fire_screen', 'flagpole', 'flute', 'folding_chair', 'football_helmet', 'forklift', 'fountain', 'fountain_pen', 'four-poster', 'freight_car', 'French_horn', 'frying_pan', 'fur_coat', 'garbage_truck', 'gasmask', 'gas_pump', 'goblet', 'go-kart', 'golf_ball', 'golfcart', 'gondola', 'gong', 'gown', 'grand_piano', 'greenhouse', 'grille', 'grocery_store', 'guillotine', 'hair_slide', 'hair_spray', 'half_track', 'hammer', 'hamper', 'hand_blower', 'hand-held_computer', 'handkerchief', 'hard_disc', 'harmonica', 'harp', 'harvester', 'hatchet', 'holster', 'home_theater', 'honeycomb', 'hook', 'hoopskirt', 'horizontal_bar', 'horse_cart', 'hourglass', 'iPod', 'iron', "jack-o'-lantern", 'jean', 'jeep', 'jersey', 'jigsaw_puzzle', 'jinrikisha', 'joystick', 'kimono', 'knee_pad', 'knot', 'lab_coat', 'ladle', 'lampshade', 'laptop', 'lawn_mower', 'lens_cap', 'letter_opener', 'library', 'lifeboat', 'lighter', 'limousine', 'liner', 'lipstick', 'Loafer', 'lotion', 'loudspeaker', 'loupe', 'lumbermill', 'magnetic_compass', 'mailbag', 'mailbox', 'maillot_(tights)', 'maillot_(tank_suit)', 'manhole_cover', 'maraca', 'marimba', 'mask', 'matchstick', 'maypole', 'maze', 'measuring_cup', 'medicine_chest', 'megalith', 'microphone', 'microwave', 'military_uniform', 'milk_can', 'minibus', 'miniskirt', 'minivan', 'missile', 'mitten', 'mixing_bowl', 'mobile_home', 'Model_T', 'modem', 'monastery', 'monitor', 'moped', 'mortar', 'mortarboard', 'mosque', 'mosquito_net', 'motor_scooter', 'mountain_bike', 'mountain_tent', 'mouse', 'mousetrap', 'moving_van', 'muzzle', 'nail', 'neck_brace', 'necklace', 'nipple', 'notebook', 'obelisk', 'oboe', 'ocarina', 'odometer', 'oil_filter', 'organ', 'oscilloscope', 'overskirt', 'oxcart', 'oxygen_mask', 'packet', 'paddle', 'paddlewheel', 'padlock', 'paintbrush', 'pajama', 'palace', 'panpipe', 'paper_towel', 'parachute', 'parallel_bars', 'park_bench', 'parking_meter', 'passenger_car', 'patio', 'pay-phone', 'pedestal', 'pencil_box', 'pencil_sharpener', 'perfume', 'Petri_dish', 'photocopier', 'pick', 'pickelhaube', 'picket_fence', 'pickup', 'pier', 'piggy_bank', 'pill_bottle', 'pillow', 'ping-pong_ball', 'pinwheel', 'pirate', 'pitcher', 'plane', 'planetarium', 'plastic_bag', 'plate_rack', 'plow', 'plunger', 'Polaroid_camera', 'pole', 'police_van', 'poncho', 'pool_table', 'pop_bottle', 'pot', "potter's_wheel", 'power_drill', 'prayer_rug', 'printer', 'prison', 'projectile', 'projector', 'puck', 'punching_bag', 'purse', 'quill', 'quilt', 'racer', 'racket', 'radiator', 'radio', 'radio_telescope', 'rain_barrel', 'recreational_vehicle', 'reel', 'reflex_camera', 'refrigerator', 'remote_control', 'restaurant', 'revolver', 'rifle', 'rocking_chair', 'rotisserie', 'rubber_eraser', 'rugby_ball', 'rule', 'running_shoe', 'safe', 'safety_pin', 'saltshaker', 'sandal', 'sarong', 'sax', 'scabbard', 'scale', 'school_bus', 'schooner', 'scoreboard', 'screen', 'screw', 'screwdriver', 'seat_belt', 'sewing_machine', 'shield', 'shoe_shop', 'shoji', 'shopping_basket', 'shopping_cart', 'shovel', 'shower_cap', 'shower_curtain', 'ski', 'ski_mask', 'sleeping_bag', 'slide_rule', 'sliding_door', 'slot', 'snorkel', 'snowmobile', 'snowplow', 'soap_dispenser', 'soccer_ball', 'sock', 'solar_dish', 'sombrero', 'soup_bowl', 'space_bar', 'space_heater', 'space_shuttle', 'spatula', 'speedboat', 'spider_web', 'spindle', 'sports_car', 'spotlight', 'stage', 'steam_locomotive', 'steel_arch_bridge', 'steel_drum', 'stethoscope', 'stole', 'stone_wall', 'stopwatch', 'stove', 'strainer', 'streetcar', 'stretcher', 'studio_couch', 'stupa', 'submarine', 'suit', 'sundial', 'sunglass', 'sunglasses', 'sunscreen', 'suspension_bridge', 'swab', 'sweatshirt', 'swimming_trunks', 'swing', 'switch', 'syringe', 'table_lamp', 'tank', 'tape_player', 'teapot', 'teddy', 'television', 'tennis_ball', 'thatch', 'theater_curtain', 'thimble', 'thresher', 'throne', 'tile_roof', 'toaster', 'tobacco_shop', 'toilet_seat', 'torch', 'totem_pole', 'tow_truck', 'toyshop', 'tractor', 'trailer_truck', 'tray', 'trench_coat', 'tricycle', 'trimaran', 'tripod', 'triumphal_arch', 'trolleybus', 'trombone', 'tub', 'turnstile', 'typewriter_keyboard', 'umbrella', 'unicycle', 'upright', 'vacuum', 'vase', 'vault', 'velvet', 'vending_machine', 'vestment', 'viaduct', 'violin', 'volleyball', 'waffle_iron', 'wall_clock', 'wallet', 'wardrobe', 'warplane', 'washbasin', 'washer', 'water_bottle', 'water_jug', 'water_tower', 'whiskey_jug', 'whistle', 'wig', 'window_screen', 'window_shade', 'Windsor_tie', 'wine_bottle', 'wing', 'wok', 'wooden_spoon', 'wool', 'worm_fence', 'wreck', 'yawl', 'yurt', 'web_site', 'comic_book', 'crossword_puzzle', 'street_sign', 'traffic_light', 'book_jacket', 'menu', 'plate', 'guacamole', 'consomme', 'hot_pot', 'trifle', 'ice_cream', 'ice_lolly', 'French_loaf', 'bagel', 'pretzel', 'cheeseburger', 'hotdog', 'mashed_potato', 'head_cabbage', 'broccoli', 'cauliflower', 'zucchini', 'spaghetti_squash', 'acorn_squash', 'butternut_squash', 'cucumber', 'artichoke', 'bell_pepper', 'cardoon', 'mushroom', 'Granny_Smith', 'strawberry', 'orange', 'lemon', 'fig', 'pineapple', 'banana', 'jackfruit', 'custard_apple', 'pomegranate', 'hay', 'carbonara', 'chocolate_sauce', 'dough', 'meat_loaf', 'pizza', 'potpie', 'burrito', 'red_wine', 'espresso', 'cup', 'eggnog', 'alp', 'bubble', 'cliff', 'coral_reef', 'geyser', 'lakeside', 'promontory', 'sandbar', 'seashore', 'valley', 'volcano', 'ballplayer', 'groom', 'scuba_diver', 'rapeseed', 'daisy', "yellow_lady's_slipper", 'corn', 'acorn', 'hip', 'buckeye', 'coral_fungus', 'agaric', 'gyromitra', 'stinkhorn', 'earthstar', 'hen-of-the-woods', 'bolete', 'ear', 'toilet_tissue']
2. **Labeling Config:**
- I have this labeling config from Label Studio:
<View>
<Image name="image" value="$image"/>
<Choices name="choice" toName="image">
<Choice value="Airplane"/>
<Choice value="Car"/>
</Choices>
</View>
3. **Mapping Instructions:**
- Map the labels from the Label Studio config to the closest matching ML model labels as follows:
1. Use the `value` attribute from each `<Choice>` tag to identify the label.
2. Find all similar and relevant labels from the ML model corresponding to each `<Choice>` label.
3. Add a `predicted_values="<relevant_label1_from_ml_model>,<relevant_label2_from_ml_model>"` attribute inside each `<Choice>` tag using only labels from the ML model.
4. **Output:**
- Provide the final labeling config with the `predicted_values` attribute added, using all relevant labels from the ML model, without any explanations.
支持的YOLO版本: YOLOv5, YOLO11及其他
YOLOv5: 该模型支持目标检测任务。请确保指定
model_path="yolov5nu.pt"(别忘了u)来使用YOLOv5模型。YOLOv8: 这些模型已通过当前ML后端成功测试。查看v8模型的完整列表。
YOLO11: YOLO11模型也已成功通过该ML后端测试。查看v11模型完整列表。
警告1: 如果您在2024年9月30日星期一最新Ultralytics更新之前使用过,必须将
ultralytics包升级至最新版本(pip install -U ultralytics)或从头重建ML后端Docker(docker-compose build --no-cache)。警告2: YOLO11模型的命名规范不使用
v。例如,使用yolo11n.pt而非yolov11n.pt,这与YOLOv8的命名规范不同。有关支持的YOLO版本和模型的完整列表,请参阅Ultralytics文档: Ultralytics Supported YOLO Models
注意:Ultralytics文档中列出的一些YOLO模型尚未使用此ML后端进行测试,但它们可能仍然有效。
您自定义的YOLO模型
您可以按照以下步骤加载自己的YOLO标签:
- 将您的模型挂载到Docker内的
/app/models/路径下。.pt - 在标注配置中的控制标签内添加
model_path=",例如:.pt"
<RectangleLabels model_path="my_model.pt">
Step by step guide: Using your own custom YOLOv8 model
You can integrate your own custom-trained YOLOv8 models with the YOLO ML backend for Label Studio. Follow these detailed steps to set up your custom model in the ML backend Docker:
步骤0:安装Label Studio并克隆此Github仓库
- 安装并运行Label Studio(或查看更多方式)。
pip install label-studio
label-studio
- 克隆Label Studio ML后端仓库并进入
yolo示例文件夹:
git clone https://github.com/HumanSignal/label-studio-ml-backend.git
cd label-studio-ml-backend/examples/yolo
步骤1:准备您的自定义YOLOv8模型
确保您的自定义YOLOv8模型保存为.pt文件,这是PyTorch模型的标准格式。
假设您的模型文件名为my_custom_model.pt。
步骤2:部署您的模型
创建'models'目录:
在您的项目根目录
yolo(与docker-compose.yml文件所在的同一目录)中, 创建一个名为models的新文件夹,并将您的my_custom_model.pt文件放入其中。yolo/ ├── docker-compose.yml ├── models/ └── my_custom_model.pt修改
docker-compose.yml挂载'models'目录:更新您的
docker-compose.yml文件,添加一个卷将本地的models目录映射到Docker容器内的/app/models目录。services: yolo: container_name: yolo ... volumes: - ./models:/app/models # 挂载本地'models'目录 environment: - ALLOW_CUSTOM_MODEL_PATH=true ...
步骤3:确保环境变量设置正确
ALLOW_CUSTOM_MODEL_PATH=true: 确保在Docker环境变量中设置此参数以允许ML后端加载自定义模型路径(默认为true)。LABEL_STUDIO_URL: 必须指定您的Label Studio实例的外部IP或域名。 如果您在本地运行Label Studio和ML后端,可以尝试设置为LABEL_STUDIO_URL=http://host.docker.internal:8080。LABEL_STUDIO_API_KEY: 需要指定您的Label Studio实例的API密钥。 您可以在Label Studio的用户账户页面上找到它。LOG_LEVEL: (可选) 设置ML后端的日志级别。可以使用DEBUG,INFO,WARNING,ERROR。
示例 docker-compose.yml:
environment:
- ALLOW_CUSTOM_MODEL_PATH=true
- LABEL_STUDIO_URL=http://host.docker.internal:8080
- LABEL_STUDIO_API_KEY=your_api_key
- LOG_LEVEL=DEBUG # optional
步骤4:在Label Studio中更新您的标注配置
在您的Label Studio项目中,通过在标注配置中使用的控制标签(例如、、等)添加model_path参数来指定自定义模型的路径。
使用进行目标检测的示例:
<View>
<Image name="image" value="$image"/>
<RectangleLabels
name="label" toName="image"
model_path="my_custom_model.pt"
model_score_threshold="0.25">
<Label value="Cat"/>
<Label value="Dog"/>
</RectangleLabels>
</View>
重要提示:
model_path:model_path应与您的自定义模型文件名匹配,且必须位于Docker容器内的/app/models目录中。- 类名映射: 确保
value属性在标签中与模型预测的类名相对应。如果不一致,使用predicted_values属性进行映射。示例:<Label value="Cat" predicted_values="feline"/> <Label value="Dog" predicted_values="canine"/> - 在哪里查找类别名称: 查看ML后端日志以获取模型预测的确切类别名称,然后您可以直接在
predicted_values属性和Label标签的value中使用这些名称。
步骤5:重启ML后端
完成这些更改后,重启ML后端以应用新的配置。
docker-compose down
docker-compose up --build
步骤6:将ML后端连接到您的Label Studio项目
- 打开您的Label Studio实例。
- 前往项目的设置页面。
- 导航至模型标签页。
- 通过输入ML后端URL连接到ML后端(如果在本地运行,很可能是
http://localhost:9090)。
步骤7:测试您的设置
向您的Label Studio项目添加一些任务(如图像或其他数据),并在标注界面中打开一个任务。 此时,机器学习后端应使用您的自定义模型生成预测结果。
常见陷阱
- 模型路径错误: 确保标注配置中的
model_path与/app/models目录内模型文件名完全一致。 - 标签不匹配:请仔细检查您在Label Studio中的标签是否与模型预测的类别一致,或者使用
predicted_values来进行映射。 - 关键点模型和model_index: 如果使用关键点模型,您需要在每个
Label标签中指定model_index参数。
训练
当前的Label Studio ML后端不支持训练YOLO模型。您需要自行手动完成训练。 或者您可以为此代码库贡献代码,为该ML后端添加训练支持功能。
使用进行分类
YOLO提供了一个分类模型,Label Studio通过Choices控制标签来支持这一功能。
更多信息:https://docs.ultralytics.com/tasks/classify/
标注配置
<View>
<Image name="image" value="$image"/>
<Choices name="choice" toName="image" model_score_threshold="0.25">
<Choice value="Airplane" predicted_values="aircraft_carrier,airliner,airship,warplane"/>
<Choice value="Car" predicted_values="limousine,minivan,jeep,sports_car,passenger_car,police_van"/>
</Choices>
</View>
参数
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
model_score_threshold |
float | 0.5 | Sets the minimum confidence threshold for detections. Objects detected with confidence below this threshold will be disregarded. Adjusting this value can help reduce false positives. |
model_path |
string | None | Path to the custom YOLO model. See more in the section Your own custom YOLO models. |
choice |
string | single | Possible values: single, single-radio, multiple. If you use choice="single" (default) you can select only one label. The ML backend will return the label with the highest confidence using argmax strategy. If you use choice="multiple" you can select multiple labels. The ML backend will return all labels with confidence above the model_score_threshold. |
例如:
<Choices name="choice" toName="image" model_score_threshold="0.25" model_path="my_model.pt">
默认模型
yolov8n-cls.pt 是默认的分类模型。
使用RectangleLabels进行目标检测
YOLO模型提供边界框检测,也称为“目标检测”。
Label Studio通过RectangleLabels控制标签支持此功能。
YOLO OBB 模型也受支持。
更多信息: https://docs.ultralytics.com/tasks/detect/
标注配置
<View>
<Image name="image" value="$image"/>
<RectangleLabels name="label" toName="image" model_score_threshold="0.25" opacity="0.1">
<Label value="Person" background="red"/>
<Label value="Car" background="blue"/>
</RectangleLabels>
</View>
参数
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
model_score_threshold |
float | 0.5 | Sets the minimum confidence threshold for detections. Objects detected with confidence below this threshold will be disregarded. Adjusting this value can help reduce false positives. |
model_path |
string | None | Path to the custom YOLO model. See more in the section Your own custom YOLO models. |
model_obb |
bool | False | Enables Oriented Bounding Boxes (OBB) mode. Typically it uses *-obb.pt yolo models. |
例如:
<RectangleLabels name="label" toName="image" model_score_threshold="0.25" model_path="my_model.pt">
默认模型
yolov8m.pt 是默认的目标检测模型。
yolov8n-obb.pt 是默认的OBB目标检测模型。
定向边界框 (YOLO OBB)
如果使用OBB模型,将自动生成定向(旋转)边界框。在RectangleLabels标签中指定model_obb="true"以启用此模式:
<RectangleLabels name="label" toName="image" model_score_threshold="0.25" model_obb="true">
更多信息:https://docs.ultralytics.com/tasks/obb/
使用PolygonLabels进行图像分割
YOLO模型提供分割检测功能,也称为"实例分割"。
Label Studio通过PolygonLabels控制标签支持这一功能。
更多信息:https://docs.ultralytics.com/tasks/segment/
标注配置
<View>
<Image name="image" value="$image"/>
<PolygonLabels name="label" toName="image" model_score_threshold="0.25" opacity="0.1">
<Label value="Car" background="blue"/>
<Label value="Person" background="red"/>
</PolygonLabels>
</View>
参数
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
model_score_threshold |
float | 0.5 | Sets the minimum confidence threshold for detections. Objects detected with confidence below this threshold will be disregarded. Adjusting this value can help reduce false positives. |
model_path |
string | None | Path to the custom YOLO model. See more in the section Your own custom YOLO models. |
例如:
<PolygonLabels name="label" toName="image" model_score_threshold="0.25" model_path="my_model.pt">
默认模型
yolov8n-seg.pt 是默认的分割模型。
使用KeyPointLabels进行关键点检测
YOLO模型提供关键点检测功能,也称为"姿态估计"。
Label Studio通过KeyPointLabels控制标签支持这一功能。
标注配置
<View>
<RectangleLabels name="keypoints_bbox" toName="image" model_skip="true">
<Label value="person"/>
</RectangleLabels>
<KeyPointLabels name="keypoints" toName="image"
model_score_threshold="0.75" model_point_threshold="0.5"
model_add_bboxes="true" model_point_size="1"
model_path="yolov8n-pose.pt"
>
<Label value="nose" predicted_values="person" model_index="0" background="red" />
<Label value="left_eye" predicted_values="person" model_index="1" background="yellow" />
<Label value="right_eye" predicted_values="person" model_index="2" background="yellow" />
<Label value="left_ear" predicted_values="person" model_index="3" background="purple" />
<Label value="right_ear" predicted_values="person" model_index="4" background="purple" />
<View>
<Label value="left_shoulder" predicted_values="person" model_index="5" background="green" />
<Label value="left_elbow" predicted_values="person" model_index="7" background="green" />
<Label value="left_wrist" predicted_values="person" model_index="9" background="green" />
<Label value="right_shoulder" predicted_values="person" model_index="6" background="blue" />
<Label value="right_elbow" predicted_values="person" model_index="8" background="blue" />
<Label value="right_wrist" predicted_values="person" model_index="10" background="blue" />
</View>
<View>
<Label value="left_hip" predicted_values="person" model_index="11" background="brown" />
<Label value="left_knee" predicted_values="person" model_index="13" background="brown" />
<Label value="left_ankle" predicted_values="person" model_index="15" background="brown" />
<Label value="right_hip" predicted_values="person" model_index="12" background="orange" />
<Label value="right_knee" predicted_values="person" model_index="14" background="orange" />
<Label value="right_ankle" predicted_values="person" model_index="16" background="orange" />
</View>
</KeyPointLabels>
<Image name="image" value="$image" />
</View>
参数
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
model_path |
string | None | Path to the custom YOLO model. See more in the section Your own custom YOLO models. |
model_score_threshold |
float | 0.5 | Sets the minimum confidence threshold for bounding box detections. Keypoints that are related to the detected bbox with a confidence below this threshold will be disregarded. |
model_point_threshold |
float | 0.0 | Minimum confidence threshold for keypoints. Keypoints with confidence below this value will be ignored. |
model_add_bboxes |
bool | True | Adds bounding boxes for detected keypoints. All keypoints will be grouped by parent bounding boxes on the region panel. See details in the tip below. |
model_point_size |
float | 1 | Size of the keypoints in pixels. Just a visual parameter. |
model_index |
int | None | Index of the keypoint in the YOLO model output starting from 0. It’s used in Label tags only to build mapping between a Label and an output point. |
例如:
<KeyPointLabels name="keypoints" toName="image"
model_path="yolov8n-pose.pt"
model_score_threshold="0.25" model_point_threshold="0.5"
model_add_bboxes="true" model_point_size="2">
默认模型
yolov8n-pose.pt 是默认的关键点检测模型。
使用边界框对关键点进行分组
在使用关键点检测时,机器学习后端会通过关联每个检测到的人或物体的边界框(bbox)对关键点进行分组。 您可以在Label Studio右侧的区域面板下查看分组情况。请注意,您可以根据需要拖放区域项目。
默认情况下,边界框会被添加到预测结果中。您可以通过设置model_add_bboxes来启用或禁用此行为:
<KeyPointLabels name="keypoints" toName="image" model_add_bboxes="false">
Tip: How to only keep keypoints and discard bounding boxes?
要在同一任务中同时启用关键点检测和边界框检测,您需要
- 在
KeyPointLabels标签中设置model_add_bboxes="false" - 移除
RectangleLabels标签。
您可以使用此标注配置来去除边界框,仅保留关键点:
<View>
<KeyPointLabels name="keypoints" toName="image"
model_score_threshold="0.75" model_point_threshold="0.5"
model_path="yolov8n-pose.pt" model_point_size="1"
model_add_bboxes="false"
>
<Label value="nose" predicted_values="person" model_index="0" background="red" />
<Label value="left_eye" predicted_values="person" model_index="1" background="yellow" />
<Label value="right_eye" predicted_values="person" model_index="2" background="yellow" />
<Label value="left_ear" predicted_values="person" model_index="3" background="purple" />
<Label value="right_ear" predicted_values="person" model_index="4" background="purple" />
<View>
<Label value="left_shoulder" predicted_values="person" model_index="5" background="green" />
<Label value="left_elbow" predicted_values="person" model_index="7" background="green" />
<Label value="left_wrist" predicted_values="person" model_index="9" background="green" />
<Label value="right_shoulder" predicted_values="person" model_index="6" background="blue" />
<Label value="right_elbow" predicted_values="person" model_index="8" background="blue" />
<Label value="right_wrist" predicted_values="person" model_index="10" background="blue" />
</View>
<View>
<Label value="left_hip" predicted_values="person" model_index="11" background="brown" />
<Label value="left_knee" predicted_values="person" model_index="13" background="brown" />
<Label value="left_ankle" predicted_values="person" model_index="15" background="brown" />
<Label value="right_hip" predicted_values="person" model_index="12" background="orange" />
<Label value="right_knee" predicted_values="person" model_index="14" background="orange" />
<Label value="right_ankle" predicted_values="person" model_index="16" background="orange" />
</View>
</KeyPointLabels>
<Image name="image" value="$image" />
</View>
点映射
如需精确控制,您可以在Label Studio配置中将关键点映射到特定标签。
每个关键点可与人物或对象的特定部位关联,
您可以使用model_index和predicted_values属性定义此映射关系。
<Label value="left_eye" predicted_values="person" model_index="1" />
<Label value="right_eye" predicted_values="person" model_index="2" />
此配置确保YOLO模型检测到的关键点在Label Studio界面中被正确标注。
对于姿态检测模型,model_index属性用于根据YOLO模型输出将关键点映射到身体的特定部位:
0: Nose 1: Left Eye 2: Right Eye 3: Left Ear 4: Right Ear
5: Left Shoulder 6: Right Shoulder 7: Left Elbow 8: Right Elbow 9: Left Wrist 10: Right Wrist
11: Left Hip 12: Right Hip 13: Left Knee 14: Right Knee 15: Left Ankle 16: Right Ankle
推荐
- 边界框可视化: 使用
model_add_bboxes参数来可视化包含关键点的边界框。这在处理多个检测到的人或物体时特别有用。 - 阈值调整: 根据您的数据集和关键点检测所需的置信度水平,调整
model_score_threshold和model_point_threshold参数。
使用VideoRectangle进行视频对象追踪
YOLO模型提供目标跟踪功能,也称为"多目标跟踪"。Label Studio通过VideoRectangle + Labels控制标签来支持这一功能。
更多信息:https://docs.ultralytics.com/modes/track/
标注配置
<View>
<Video name="video" value="$video"/>
<VideoRectangle name="box" toName="video" model_tracker="botsort" model_conf="0.25" model_iou="0.7" />
<Labels name="label" toName="video">
<Label value="Person" background="red"/>
<Label value="Car" background="blue"/>
</Labels>
</View>
追踪器
https://docs.ultralytics.com/modes/track/?h=track#tracker-selection
与Ultralytics YOLO配合使用的最佳跟踪器取决于您的具体需求。
默认的跟踪器是BoT-SORT,它通常适用于大多数场景。
不过,如果您正在寻找具有不同优势的替代方案, ByteTrack 是另一个可以轻松配置的不错选择。 ByteTrack 以在多目标跟踪中的高性能而闻名, 特别是在目标外观变化和重现的情况下。
两种追踪器都可以通过YAML配置文件进行自定义,以适应您的特定使用场景。
您可以在控制标签中指定追踪器:
边界框参数
追踪器适用于目标检测模型(边界框)。
第一步是检测边界框,第二步是跟踪它们(在帧间寻找相同的框)。这些参数与第一步——边界框检测相关。
了解更多关于这些参数的信息: https://docs.ultralytics.com/modes/track/?h=track#tracking-arguments
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
model_conf |
float | 0.25 | Sets the minimum confidence threshold for detections. Objects detected with confidence below this threshold will be disregarded. Adjusting this value can help reduce false positives. |
model_iou |
float | 0.7 | Intersection Over Union (IoU) threshold for Non-Maximum Suppression (NMS). Lower values result in fewer detections by eliminating overlapping boxes, useful for reducing duplicates. |
model_tracker |
string | botsort |
Sets the tracker to use for multi-object tracking. Options include botsort, bytetrack, or a custom YAML file. |
model_path |
string | None | Path to the custom YOLO model. See more in the section Your own custom YOLO models. |
例如:
<VideoRectangle name="label" toName="video" model_tracker="botsort" model_conf="0.25" model_iou="0.7" />
追踪器参数
有关跟踪器参数的示例,请参阅 https://github.com/ultralytics/ultralytics/tree/main/ultralytics/cfg/trackers。
主要参数是 model_tracker,可以设置为
botsortbytetrack- 或者放入
models目录中的任何自定义yaml文件的名称(设置此参数时不要包含文件扩展名.yaml)。
只要它们在yaml文件中可用,您可以直接从标注配置中指定跟踪器参数。所有参数应以botsort_或bytetrack_为前缀。
例如:
<VideoRectangle
name="label" toName="video"
model_tracker="botsort"
botsort_track_low_thresh="0.1" botsort_track_high_thresh="0.2"
/>
默认模型
yolov8n.pt 是默认的目标检测模型。
推荐
视频目标追踪是一项计算密集型任务。建议使用小型模型如
yolov8n.pt进行实时追踪,但它们的准确性可能不如大型模型。Label Studio对机器学习后端请求设有超时限制。您可以在Label Studio后端设置中调整超时时间。
- 或者使用CLI工具异步运行预测。
使用TimelineLabels进行视频时序分类
该ML后端支持Label Studio中控制标签的时间序列多标签视频分类功能。
提供两种模式:
- 简单模式: 在简单模式下,模型使用预训练的YOLO类别生成预测,无需额外训练。
- 可训练:在可训练模式下,模型可以通过小样本学习在Label Studio中提交的自定义标签和标注上进行训练,因为训练是基于少量标注进行的。
标注配置
<View>
<Video name="video" value="$video"/>
<TimelineLabels
name="label" toName="video"
model_trainable="false" model_score_threshold="0.25">
<Label value="Ball" predicted_values="soccer_ball" />
<Label value="hamster" />
</TimelineLabels>
</View>
模型训练
有关使用TimelineLabels机器学习后端的更多详情,包括模型训练和调整神经网络分类器参数,请参阅README_TIMELINE_LABELS.md。
默认模型
yolov8n-cls.pt 是简单模式下的默认分类模型。
运行YOLO机器学习后端
使用Docker运行(推荐)
使用预构建的镜像在
http://localhost:9090上启动机器学习后端:docker-compose up验证后端是否正在运行
$ curl http://localhost:9090/ {"status":"UP"}在Label Studio中创建一个项目。然后从项目设置的模型页面,连接模型。默认URL是
http://localhost:9090。
从源码构建(高级)
要从源代码构建ML后端,您需要克隆代码仓库并构建Docker镜像:
docker-compose build
不使用Docker运行(高级)
要在不使用Docker的情况下运行ML后端,您需要克隆代码库并使用pip安装所有依赖项:
python -m venv ml-backend
source ml-backend/bin/activate
pip install -r requirements-base.txt
pip install -r requirements.txt
然后你可以启动ML后端:
label-studio-ml start ./dir_with_your_model
此外,您可以查看Dockerfile获取额外依赖项并手动安装它们。
参数
在运行容器之前,请检查docker-compose.yml文件中的environment部分。所有可用参数都在那里列出。
注意:您可以直接在标注配置中使用许多YOLO模型参数,例如
model_path或model_score_threshold。
终端命令行界面
概述
该命令行界面(CLI)工具便于将YOLO模型与Label Studio集成,用于机器学习预测。 它提供了一种在Label Studio管理的任务上运行YOLO预测的替代方法, 特别适用于处理长视频或大型数据集。
直接从CLI运行模型预测有助于避免Label Studio与ML后端之间的连接超时问题,这类问题可能在长时间处理过程中发生。
何时使用CLI
在处理大型媒体文件(如长视频)时,处理时间可能会很长。如果请求耗时过长,Label Studio可能会中断与ML后端的连接,导致预测结果不完整。
通过运行此CLI工具,您可以异步执行模型预测,而无需Label Studio与后端保持持续连接。 这确保即使是大规模或复杂的任务也能完整处理,并在完成后通过SDK将预测结果保存至Label Studio。
工作原理
- Label Studio 连接: 该工具通过提供的API密钥和URL连接到正在运行的Label Studio实例。
- 任务准备: 任务可以直接通过JSON文件提供,或作为任务ID列表提供。如果提供了任务ID,该工具会从Label Studio获取任务数据。
- 模型加载: 根据项目配置加载并初始化YOLO模型。
- 预测流程: 对于每个任务,YOLO模型会生成预测结果,随后这些结果会被后处理成Label Studio所需的格式。
- 异步上传: 生成的预测结果会被回传到Label Studio,这样即使处理大型任务也不会超时。
使用说明
python cli.py --ls-url http://localhost:8080 --ls-api-key your_api_key --project 1 --tasks tasks.json
或
python cli.py --ls-url http://localhost:8080 --ls-api-key YOUR_API_KEY --project 1 --tasks 1,2,3
参数
--ls-url: Label Studio实例的URL地址。默认为http://localhost:8080。--ls-api-key: Label Studio的API密钥。用于验证连接。--project: 管理任务的Label Studio项目ID。默认为1。--tasks:- 包含任务列表或任务ID的JSON文件路径,例如:
tasks_ids.json
[1,2,3]tasks.json
[{"id": 1, "data": {"image": "https://example.com/1.jpg"}}, {"id": 2, "data": {"image": "https://example.com/2.jpg"}}]- 如果未提供文件,可以直接传递以逗号分隔的任务ID列表,例如:
1,2,3
日志记录
使用 LOG_LEVEL=DEBUG 获取详细日志。示例:
LOG_LEVEL=DEBUG python cli.py --ls-url http://localhost:8080 --ls-api-key YOUR_API_KEY --project 2 --tasks 1,2,3
开发者指南
项目架构和开发指南详见README_DEVELOP.md文件。