I want to load my own data to Net, and there are 1000 silhouette images as input and the corresponding 1000 12d vectors as target in my data. The format of silhouette images is .png
in
folder /hsdata_train/
, the format of 12d vector is .txt
in file
/data/txt/list_1000.txt
.
The following is my code. What should I do? Please help, thanks!
text_path = '/data/txt/list_1000.txt'
float_data = []
with open(text_path) as f:
text_data = f.readlines()
for line_index in range(len(text_data)):
line = text_data[line_index].strip('\n')
words = line.split()
del words[0]
float_data.append(words)
target_train = torch.from_numpy(np.asfarray(float_data))
# The output of torchvision datasets are PILImage images of range [0, 1].
# We transform them to Tensors of normalized range [-1, 1]
transform=transforms.Compose([transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
image_train = torchvision.datasets.ImageFolder(root='/home/pangdan/hsdata_train', transform=transform)
train = torch.utils.data.TensorDataset(image_train, target_train)
trainloader = torch.utils.data.DataLoader(train, batch_size=4,
shuffle=True, num_workers=2)