import txt_file_maker
import dataset_maker
import YOLO
import torch
from torch.utils.data import DataLoader
import time

image_paths = ['./datasets/VOCtrainval_06-Nov-2007/VOCdevkit/VOC2007', './datasets/VOCtrainval_11-May-2012/VOCdevkit/VOC2012', './datasets/VOCtest_06-Nov-2007/VOCdevkit/VOC2007', './datasets/VOC2012test/VOCdevkit/VOC2012']
txt_paths = ["./datasets/txt/voc2007trainval.txt", "./datasets/txt/voc2012trainval.txt", "./datasets/txt/voc2007test.txt", "./datasets/txt/voc2012test.txt"]

txt_make = 0 # If this is the first run, you should change it to 1 to make txt file to be used for making dataset

if txt_make == 1:
    print('txt file making start')
    for i in range(len(image_paths)):
        txt_file_maker.maker(image_path=image_paths[i], txt_path=txt_paths[i])
else: print("txt file already made")

print('txt file making complete!')

# YoloDataset(root=file_root, list_file='./codes/lab8/Generate_dataset/voc2007+2012.txt', train=True)

print('dataset making start!')

VOC2007_trainset = dataset_maker.YoloDataset(root=image_paths[0], list_file=txt_paths[0], train=True)
train_loader = DataLoader(VOC2007_trainset, batch_size=32, shuffle=True, num_workers=4)

print('dataset making complete!')

model = YOLO.yolo()

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)

learning_rate = 1e-4
optimizer = torch.optim.SGD(model.parameters(), lr=learning_rate, momentum=0.9, weight_decay=5e-4)
#optimizer.load_state_dict(state_dict['optimizer'])

print('pre_train_complete')
criterion = YOLO.yoloLoss(l_coord=5, l_noobj=0.5)

best = 1e+30
num_epochs = 10
print("training start!")

loss_per_epoch = 0

for i in range(num_epochs):
    model.train()
    start = time.time()
    for j, (img, target) in enumerate(train_loader, 0):
        img = img.to(device)
        target = target.to(device)

        optimizer.zero_grad()
        output = model.forward(img)
        loss = criterion.forward(output, target)
        loss_per_epoch += loss

        loss.backward()

        optimizer.step()
    print("Epoch {} loss : {} , Elapsed time : {}".format(i, loss_per_epoch / j, time.time() - start))
    loss_per_epoch = 0

If I run the code, there is broken pipe error.
I printed out the processing steps as like in above code.
txt file already made
txt file making complete!
dataset making start!
dataset making complete!
pre_train_complete
training start!
txt file already made
txt file making complete!
dataset making start!
dataset making complete!
pre_train_complete
training start!
However, I only can figure out that it runs the code twice. I don’t know why.