Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list index out of range #575

Open
fatemehmomeni80 opened this issue Feb 7, 2024 · 0 comments
Open

list index out of range #575

fatemehmomeni80 opened this issue Feb 7, 2024 · 0 comments

Comments

@fatemehmomeni80
Copy link

Hello, I came to update my data set, which is the data set of my construction, what should I do with the following problem? First, I typed these codes:import os
import pandas as pd

train_path = '/content/deep-person-reid/reid-data/new_dataset/bulding/train'
gallery_path = '/content/deep-person-reid/reid-data/new_dataset/bulding/gallery'
query_path = '/content/deep-person-reid/reid-data/new_dataset/bulding/query'

file_extension = 'jpg'

train_files = [os.path.join(train_path, f) for f in os.listdir(train_path) if f.endswith(f".{file_extension}")]
gallery_files = [os.path.join(gallery_path, f) for f in os.listdir(gallery_path) if f.endswith(f".{file_extension}")]
query_files = [os.path.join(query_path, f) for f in os.listdir(query_path) if f.endswith(f".{file_extension}")]

data = {'Filepath': train_files + gallery_files + query_files,
'Label': ['Train'] * len(train_files) + ['Gallery'] * len(gallery_files) + ['Query'] * len(query_files)}

df = pd.DataFrame(data)

df.to_csv('/content/deep-person-reid/reid-data/new_dataset/buldingreferences.csv', index=False)

import os
import os.path as osp
from torchreid.data import ImageDataset
import random
import pandas as pd
import copy

class NewDataset(ImageDataset):

dataset_dir = "new_dataset"

def init(self, root='', **kwargs):
self.root = osp.abspath(osp.expanduser(root))
self.dataset_dir = osp.join(self.root, self.dataset_dir)

#===========================================================

# extract csv info

folder_path = "/content/deep-person-reid/reid-data/new_dataset/bulding" # Change the path to the dataset
refs  = pd.read_csv("{}references.csv".format(folder_path))
paths  = os.listdir(folder_path)
print(refs.columns)

# Get some data
pid_pics = refs["Filepath"]  
  # Number of pics per id
pids = refs.shape[0] # Number of identities

# Generate batches of paths by its person id
batches = list()
for i in range(pids):
    batches.append([folder_path+path for path in paths if path.startswith("{}-".format(i+1))])

# Create a random split shuffle of the query/gallery paths

query_paths = list()
gallery_paths = list()

split_size = 0.8 # Query-Gallery split, usually 0.2 : 0.8

for i in range(pids):
    gallery_elements = int(len(batches[i])*split_size)
    gallery_paths.append(random.sample(batches[i], gallery_elements))
    query_paths.append([e for e in batches[i] if e not in gallery_paths[i]])

# Generate the required variables

#train = list()
query = [(e, i, 0) for i in range(pids) for e in query_paths[i]] # camera view 0
gallery = [(e, i, 1) for i in range(pids) for e in gallery_paths[i]] # camera view 1
train = copy.deepcopy(query) + copy.deepcopy(gallery) # dummy variable


super(NewDataset, self).__init__(train, query, gallery, **kwargs)

#Register your own dataset

torchreid.data.register_image_dataset('h2', NewDataset)

from torchreid.data import ImageDataManager

datamanager = ImageDataManager(
root='reid-data',
sources='h2',
targets='h2',
height=256,
width=128,
batch_size_train=32,
train_sampler='RandomIdentitySampler',
transforms=['random_flip', 'random_crop']
)

error is:

Building train transforms ...

resize to 256x128
random flip
random crop (enlarge to 288x144 and crop 256x128)
to torch tensor of range [0, 1]
normalization (mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
Building test transforms ...
resize to 256x128
to torch tensor of range [0, 1]
normalization (mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
=> Loading train (source) dataset
Index(['Filepath', 'Label'], dtype='object')
IndexError Traceback (most recent call last)

in <cell line: 3>()
1 from torchreid.data import ImageDataManager
2
----> 3 datamanager = ImageDataManager(
4 root='reid-data',
5 sources='h2',

4 frames

/content/deep-person-reid/torchreid/data/datasets/dataset.py in init(self, train, query, gallery, transform, k_tfm, mode, combineall, verbose, **kwargs)
55 # 4-tuple (img_path(s), pid, camid, dsetid) by
56 # adding a dataset indicator "dsetid"
---> 57 if len(train[0]) == 3:
58 train = [(*items, 0) for items in train]
59 if len(query[0]) == 3:

IndexError: list index out of range

why??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant