RetinaNet for satellite image based object detection - annotation assignment error

28 Views Asked by At

Currently trying to construct a RetinaNet model for training on a custom data set. The custom data set itself constitutes of 1000 randomly selected samples from a pre-tiled image directory. There are 3 classes, which are mapped in a directory containing .xml annotation files.

I'm experiencing an error with sufficiently calling in the respective xml files per image, after creating test and train datasets within the custom directory. Not entirely sure what I'm doing is wrong, but any assistance would be greatly appreciated! Thanks in advance.

Data seperation stage - Train and test specification from custom_images directory:

train_images = '.../custom_images/'
train_annotations = '.../training_data/labels/'

test_images = '...' +'test_images/'
if os.path.exists(test_images):
shutil.rmtree(test_images)
os.makedirs(test_images)

test_annotations = '...' +'test_annotations/'
if os.path.exists(test_annotations):
shutil.rmtree(test_annotations)
os.makedirs(test_annotations)

random.seed(1234)
idx = random.sample(range(800), 200)

for img in np.array(sorted(os.listdir(train_images)))\[idx\]:
shutil.move(train_images + img, test_images + img)

for annot in np.array(sorted(os.listdir(train_annotations)))\[idx\]:
shutil.move(train_annotations + annot, test_annotations + annot)

Model training stage:

for epoch in range(num_epochs):
start = time.time()
model.train()

i = 0    
epoch_loss = 0

for images, targets in train_data_loader:

    images = list(image.to(device) for image in images)
    targets = [{k: v.to(device) for k, v in t.items()} for t in targets]
    loss_dict = model(images, targets) 
    losses = sum(loss for loss in loss_dict.values()) 
    i += 1
    optimiser_2.zero_grad()
    losses.backward()
    optimiser_2.step()   
    epoch_loss += losses 

print(epoch_loss, f'time: {time.time() - start}')

Runtime error:

FileNotFoundError                         Traceback (most recent call last)
 \<ipython-input-18-154109997ba4\> in \<cell line: 3\>()
7     i = 0
8     epoch_loss = 0
\----\> 9     for images, targets in train_data_loader:
10
11         images = list(image.to(device) for image in images)

FileNotFoundError: \[Errno 2\] No such file or directory: 'train_annotations/000000000.xml'
0

There are 0 best solutions below