MMpretrain使用Tiny ImageNet数据集

Tiny ImageNet是ImageNet的子集,ImageNet太大了,训练一次要好几天,于是准备用Tiny ImageNet代替ImageNet,但是MMPretrain项目里面用的全部都是ImageNet,需要做一些修改才能使用Tiny ImageNet.

/mmpretrain/mmpretrain/datasets/imagenet.py里面列出了ImageNet的两种格式:

        imagenet
        ├── train
        │   ├──class_x
        |   |   ├── x1.jpg
        |   |   ├── x2.jpg
        |   |   └── ...
        │   ├── class_y
        |   |   ├── y1.jpg
        |   |   ├── y2.jpg
        |   |   └── ...
        |   └── ...
        ├── val
        │   ├──class_x
        |   |   └── ...
        │   ├── class_y
        |   |   └── ...
        |   └── ...
        └── test
            ├── test1.jpg
            ├── test2.jpg
            └── ...

或者:

        imagenet
        ├── train
        │   ├── x1.jpg
        │   ├── y1.jpg
        │   └── ...
        ├── val
        │   ├── x3.jpg
        │   ├── y3.jpg
        │   └── ...
        ├── test
        │   ├── test1.jpg
        │   ├── test2.jpg
        │   └── ...
        └── meta
            ├── train.txt
            └── val.txt

编写一个python小程序将解压后的Tiny ImageNet转化为上面两种格式种的任意一种即可:

修改/mmpretrain/mmpretrain/datasets/categories.py文件,在里面加上下面的TINY_IMAGENET_CATEGORIES元组:

TINY_IMAGENET_CATEGORIES = (
    'Egyptian cat',
    'reel',
    'volleyball',
    'rocking chair, rocker',
    'lemon',
    'bullfrog, Rana catesbeiana',
    'basketball',
    'cliff, drop, drop-off',
    'espresso',
    "plunger, plumber's helper",
    'parking meter',
    'German shepherd, German shepherd dog, German police dog, alsatian',
    'dining table, board',
    'monarch, monarch butterfly, milkweed butterfly, Danaus plexippus',
    'brown bear, bruin, Ursus arctos',
    'school bus',
    'pizza, pizza pie',
    'guinea pig, Cavia cobaya',
    'umbrella',
    'organ, pipe organ',
    'oboe, hautboy, hautbois',
    'maypole',
    'goldfish, Carassius auratus',
    'potpie',
    'hourglass',
    'seashore, coast, seacoast, sea-coast',
    'computer keyboard, keypad',
    'Arabian camel, dromedary, Camelus dromedarius',
    'ice cream, icecream',
    'nail',
    'space heater',
    'cardigan',
    'baboon',
    'snail',
    'coral reef',
    'albatross, mollymawk',
    "spider web, spider's web",
    'sea cucumber, holothurian',
    'backpack, back pack, knapsack, packsack, rucksack, haversack',
    'Labrador retriever',
    'pretzel',
    'king penguin, Aptenodytes patagonica',
    'sulphur butterfly, sulfur butterfly',
    'tarantula',
    'lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens',
    'pop bottle, soda bottle',
    'banana',
    'sock',
    'cockroach, roach',
    'projectile, missile',
    'beer bottle',
    'mantis, mantid',
    'freight car',
    'guacamole',
    'remote control, remote',
    'European fire salamander, Salamandra salamandra',
    'lakeside, lakeshore',
    'chimpanzee, chimp, Pan troglodytes',
    'pay-phone, pay-station',
    'fur coat',
    'alp',
    'lampshade, lamp shade',
    'torch',
    'abacus',
    'moving van',
    'barrel, cask',
    'tabby, tabby cat',
    'goose',
    'koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus',
    'bullet train, bullet',
    'CD player',
    'teapot',
    'birdhouse',
    'gazelle',
    "academic gown, academic robe, judge's robe",
    'tractor',
    'ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle',
    'miniskirt, mini',
    'golden retriever',
    'triumphal arch',
    'cannon',
    'neck brace',
    'sombrero',
    'gasmask, respirator, gas helmet',
    'candle, taper, wax light',
    'desk',
    'frying pan, frypan, skillet',
    'bee',
    'dam, dike, dyke',
    'spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish',
    'police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria',
    'iPod',
    'punching bag, punch bag, punching ball, punchball',
    'beacon, lighthouse, beacon light, pharos',
    'jellyfish',
    'wok',
    'potter\'s wheel',
    'sandal',
    'pill bottle',
    'butcher shop, meat market',
    'slug',
    'hog, pig, grunter, squealer, Sus scrofa',
    'cougar, puma, catamount, mountain lion, painter, panther, Felis concolor',
    'crane',
    'vestment',
    "dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk",
    'cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM',
    'mushroom',
    'jinrikisha, ricksha, rickshaw',
    'water tower',
    'chest',
    'snorkel',
    'sunglasses, dark glasses, shades',
    'fly',
    'limousine, limo',
    'black stork, Ciconia nigra',
    'dugong, Dugong dugon',
    'sports car, sport car',
    'water jug',
    'suspension bridge',
    'ox',
    'ice lolly, lolly, lollipop, popsicle',
    'turnstile',
    'Christmas stocking',
    'broom',
    'scorpion',
    'wooden spoon',
    'picket fence, paling',
    'rugby ball',
    'sewing machine',
    'steel arch bridge',
    'Persian cat',
    'refrigerator, icebox',
    'barn',
    'apron',
    'Yorkshire terrier',
    'swimming trunks, bathing trunks',
    'stopwatch, stop watch',
    'lawn mower, mower',
    'thatch, thatched roof',
    'fountain',
    'black widow, Latrodectus mactans',
    'bikini, two-piece',
    'plate',
    'teddy, teddy bear',
    'barbershop',
    'confectionery, confectionary, candy store',
    'beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon',
    'scoreboard',
    'orange',
    'flagpole, flagstaff',
    'American lobster, Northern lobster, Maine lobster, Homarus americanus',
    'trolleybus, trolley coach, trackless trolley',
    'drumstick',
    'dumbbell',
    'brass, memorial tablet, plaque',
    'bow tie, bow-tie, bowtie',
    'convertible',
    'bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis',
    'orangutan, orang, orangutang, Pongo pygmaeus',
    'American alligator, Alligator mississipiensis',
    'centipede',
    'syringe',
    'go-kart',
    'brain coral',
    'sea slug, nudibranch',
    'cliff dwelling',
    'mashed potato',
    'viaduct',
    'military uniform',
    'pomegranate',
    'chain',
    'kimono',
    'comic book',
    'trilobite',
    'bison',
    'pole',
    'boa constrictor, Constrictor constrictor',
    'poncho',
    'bathtub, bathing tub, bath, tub',
    'grasshopper, hopper',
    'walking stick, walkingstick, stick insect',
    'Chihuahua',
    'tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui',
    'lion, king of beasts, Panthera leo',
    'altar',
    'obelisk',
    'beaker',
    'bell pepper',
    'bannister, banister, balustrade, balusters, handrail',
    'bucket, pail',
    'magnetic compass',
    'meat loaf, meatloaf',
    'gondola',
    'standard poodle',
    'acorn',
    'lifeboat',
    'binoculars, field glasses, opera glasses',
    'cauliflower',
    'African elephant, Loxodonta africana')

最后,将相关模型文件里面的num_classes从1000改成200,就可以运行了.

posted @ 2024-10-28 14:38  MSTK  阅读(31)  评论(0编辑  收藏  举报