Hi everyone,
I am training a CNN to detect a specific type of skin cancer. I also have a series of attributes per image, such as the age and sex of the patient that corresponds to the particular image.
I explain the data flow in the diagram above:
-
The data from the first Data Loader (images ) flows through the CNN, then gets flattened and passed through the linear layer.
-
The data from the second Data Loader (attributes) needs to get appended to the flattened structure that goes from a shape of (batch_size, 240) to a shape of (batch_size, 259).
The question is how to loop over the 2 different Data Loaders to achieve this?
#defining trainloader with images
mini_b = torch.utils.data.DataLoader(torch.utils.data.TensorDataset(tX_train, ty_train),
batch_size=100, shuffle=False)
#defining trainloader with attributes
mini_b2 = torch.utils.data.DataLoader(torch.utils.data.TensorDataset(ext_data_tensor),
batch_size=100, shuffle=False)
#training loop
for i in range(500):
#iterating through data, one batch at a time
for x_j, y_j in mini_b:
#performing one training step
out = t_step(x_j, y_j, cnn1, opt1)
if i%10 == 0:
print("Epoch: {}, Loss: {:.4f}".format(i, out))