I am trying to increase my CNN’s performance and thus i decided to “play” with some transformations in order to see how they affect my model. I read that FiveCrop() and TenCrop() might help because they generate extra data to train on. However, when i try to train the model, using one of the transformations mentioned above, i get the following error:
TypeError: pic should be PIL Image or ndarray. Got <class ‘tuple’>
In the documentation of those transformations, it only states a note for the test procedure, any idea how to fix this?
I assume the error is raised, since you are passing multiple inputs returned by the TenCrop transformation?
If that’s the case, you could add the Normalize operation to the transforms.Lambda call as:
transforms.Lambda(lambda crops: torch.stack([transforms.Normalize(mean=..., std=...)(transforms.ToTensor()(crop)) for crop in crops]))
or alternatively add another transforms.Lambda as:
trans = transforms.Compose([transforms.Resize(256),
transforms.TenCrop(224), # this is a list of PIL Images
transforms.Lambda(lambda crops: torch.stack([transforms.ToTensor()(crop) for crop in crops])),
torch.stack([transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])(t) for t in tensors]))
I have another question: Applying TenCrop transforms and using batch (say 16) loading creates a batch with the dimension torch.Size([16, 10, 3, 224, 224]). This means I have 160 images when I reshape it to BCWH, ten of each. I think will be to large a batch size to use and it will also make the batch distribution unrepresentative of the entire dataset.
I am working with ChestXray data. I have found a model on Github.
Link GitHub - arnoweng/CheXNet: A pytorch reimplementation of CheXNet
I have downloaded the pre-trained model and loaded it in CUDA-based GPU. Now I want to test the code by using an image dataset. I believe the ChestXrayDataSet function is working properly. and I am using ChestXrayDataSet for test_dataset generation. Then I have used the DataLoader of PyTorch for creating the test_loader variable. Up to this everything works fine.
But when I’m using the enumerate in test_loader it is creating an error. I believe there is a problem with my lambda function in the test_dataset variable or the problem lies in the ChestXrayDataSet function. I have added the ChestXrayDataSet function and the other two images with errors!