Hi all, especially expert coders. I tried to write the following as a Python list comprehension but failed.
r = []
for mbatch,mtarget in training_generator_mem():
pred = modelR(mbatch.cuda()) #Get the predictions on GPU
lossbyfp = [lossfn(pred[:,:,j],mtarget[:,:,j].cuda()).item() for j in range(5)] #Get the loss for each of 5 planes in pred
r.append(lossbyfp) #make a list out of the many lossbyfp
# r is size bs by 5.
The problem is that pred should be computed only once, and then the 5 losses derived from it. But I do not see the way to use pred as an intermediate result inside a list comprehension.
Thanks for your help!