chou141253/FGVC-HERBS

CUB-200-2011 dataset

Opened this issue · 2 comments

Hi, thank you very much for the code. When I want to run python main.py with CUB-200-2011 dataset --c . /configs/config.yaml, I realized that the CUB-200-2011 dataset does not have a
tain/
│ ├── class1/
│ │ ├── img001.jpg
│ │ ├── img002.jpg
│ │ └── ....
│ ├── class2/ │ ├── class2/
│ │ ├── img001.jpg
│ │ ├── img002.jpg
I would like to ask if these training images are processed by myself, or where can I download them directly?

This is a simple task. Here is my code. I created a new folder called images_train_test, then used soft link to put the images into two folders train and test.

#!/usr/bin/env python

coding: utf-8

In[1]:

import os
import pandas
import numpy as np
import shutil

In[18]:

root = os.getcwd()

print output to the console

print(root)

In[10]:

fn = 'train_test_split.txt'
f = open(fn,"r")
train_test_split = f.readlines()
train_test_split = [x.strip() for x in train_test_split]
#print(train_test_split[:5])
image_ids = [int(x.split(' ')[0]) for x in train_test_split]
train_or_test = [int(x.split(' ')[1]) for x in train_test_split]
print(image_ids[-5:],train_or_test[-5:])

In[9]:

fn = 'images.txt'
f = open(fn,"r")
images = f.readlines()
images = [x.strip() for x in images]
#print(train_test_split[:5])
image_ids2 = [int(x.split(' ')[0]) for x in images]
image_paths = [x.split(' ')[1] for x in images]
print(image_ids2[-5:],image_paths[-5:])

In[11]:

print(image_ids==image_ids2)

In[21]:

if not os.path.exists('images_train_test'):
os.makedirs('images_train_test')
if not os.path.exists('images_train_test/train'):
os.makedirs('images_train_test/train')
if not os.path.exists('images_train_test/test'):
os.makedirs('images_train_test/test')

In[22]:

for i in range(len(image_ids)):
print(i,image_paths[i],train_or_test[i])

src_path = root +'/images/'+image_paths[i]
if not os.path.exists(src_path):
    print(i,src_path,"not existed")

if train_or_test[i]==1:
    dest_path = root +'/images_train_test/train/'+image_paths[i]
else: 
    dest_path = root +'/images_train_test/test/'+image_paths[i]
    
dest_dir = os.path.dirname(dest_path)
if not os.path.exists(dest_dir):
    os.makedirs(dest_dir) 
    
linkcmd = "ln -s {} {}".format(src_path,dest_path) 
os.system(linkcmd) 

In[ ]:

Here is the code to prepare the dataset.
prepare_dataset.zip