pyaf / DenseNet-MURA-PyTorch

Implementation of DenseNet model on Standford's MURA dataset using PyTorch
https://medium.com/@pyaf/implementing-densenet-on-mura-using-pytorch-f39e92566815
MIT License
74 stars 33 forks source link

ModuleNotFoundError: No module named 'torchnet' #5

Open calm-focus opened 6 years ago

calm-focus commented 6 years ago

File "main.py", line 16, in dataloaders = get_dataloaders(study_data, batch_size=1) File "/home/zli/PycharmProjects/DenseNet-MURA-PyTorch/pipeline.py", line 79, in get_dataloaders image_datasets = {x: ImageDataset(data[x], transform=data_transforms[x], study_level=study_level) for x in data_cat} File "/home/zli/PycharmProjects/DenseNet-MURA-PyTorch/pipeline.py", line 79, in image_datasets = {x: ImageDataset(data[x], transform=data_transforms[x], study_level=study_level) for x in data_cat} TypeError: init() got an unexpected keyword argument 'study_level'

When I run python main.py, I got the above error. Do you know how to fix it?

calm-focus commented 6 years ago

For class ImageDataset(Dataset), there is no argument 'study_level' in "def init(self, df, transform=None):"

pyaf commented 6 years ago

Hey @Zli1893 , just remove the study_level arg from image_datasets = {x: ImageDataset(data[x], transform=data_transforms[x], study_level=study_level) for x in data_cat} line

I've fixed the issue, you can see updated code here: https://github.com/pyaf/DenseNet-MURA-PyTorch/blob/master/pipeline.py

pyaf commented 6 years ago

Let me know if you still face any error.

calm-focus commented 6 years ago

@pyaf I fix the above issue, but there is another error. File "main.py", line 43, in model = densenet169(pretrained=True) File "/home/zli/PycharmProjects/DenseNet-MURA-PyTorch/densenet.py", line 22, in densenet169 *kwargs) File "/home/zli/PycharmProjects/DenseNet-MURA-PyTorch/densenet.py", line 95, in init bn_size=bn_size, growth_rate=growth_rate, drop_rate=drop_rate) File "/home/zli/PycharmProjects/DenseNet-MURA-PyTorch/densenet.py", line 51, in init layer = _DenseLayer(num_input_features + i growth_rate, growth_rate, bn_size, drop_rate) File "/home/zli/PycharmProjects/DenseNet-MURA-PyTorch/densenet.py", line 30, in init self.add_module('norm.1', nn.BatchNorm2d(num_input_features)), File "/home/zli/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 169, in add_module raise KeyError("module name can't contain \".\"") KeyError: 'module name can\'t contain "."' Thank you

calm-focus commented 6 years ago

I have changed norm.1 into norm1, then I got this error Epoch 1/5

Traceback (most recent call last): File "main.py", line 51, in model = train_model(model, criterion, optimizer, dataloaders, scheduler, dataset_sizes, num_epochs=5) File "/home/zli/PycharmProjects/DenseNet-MURA-PyTorch/train.py", line 52, in train_model confusion_matrix[phase].add(preds, labels.data) File "/home/zli/.local/lib/python3.6/site-packages/torchnet/meter/confusionmeter.py", line 44, in add assert predicted.shape[0] == target.shape[0], \ IndexError: tuple index out of range

pyaf commented 6 years ago

do some debugging, let me know the cause.

pyaf commented 6 years ago

Hey, did you find the bug?

calm-focus commented 6 years ago

@pyaf Sorry, I have not found the bug yet. I still got the same error. Did you run it successfully?

NazarovAV commented 6 years ago

@Zli1893 you may try adding preds = preds.view(-1) after line 50 and after line 101 in train.py and them fixing lines 53, 54: epoch_loss = running_loss.item() / dataset_sizes[phase] epoch_acc = running_corrects.item() / dataset_sizes[phase] and lines 105, 106: loss = running_loss.item() / dataset_sizes[phase] acc = running_corrects.item() / dataset_sizes[phase] otherwise accuracy will will not be calculated

John1231983 commented 6 years ago

Hi. I only can download MURA-v1.1 and I have an error when training

    image = pil_loader(study_path + 'image%s.png' % (i+1))
  File "/home/john/anaconda3/lib/python3.6/site-packages/torchvision/datasets/folder.py", line 128, in pil_loader
    with open(path, 'rb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'MURA-v1.1/train/XR_WRIST/patient07840/study2_negative/image4.png'
pyaf commented 6 years ago

@John1231983 Try checking out the path of your dataset. try giving absolute path instead of relative one. That may fix the issue.

John1231983 commented 6 years ago

Hi. Because i am using mura 1.1 so some files are missing comparison with mura 1.0. I guess problem is that image = pil_loader(study_path + 'image%s.png' % (i+1)) . I ran after 100 iters and it has that error

pyaf commented 6 years ago

look into utils.py file, modify the functions accordingly.

pbou commented 5 years ago

There are 4 hidden files in MURA 1.1 for patient07840, which are counted towards the expected number of file in the folder, but do not follow the expected pattern (and are not valid). The easiest fix is to delete these files:

MURA-v1.1/train/XR_WRIST/patient07840/study1_negative/._image1.png
MURA-v1.1/train/XR_WRIST/patient07840/study2_negative/._image3.png
MURA-v1.1/train/XR_WRIST/patient07840/study2_negative/._image1.png
MURA-v1.1/train/XR_WRIST/patient07840/study2_negative/._image2.png
rushin682 commented 5 years ago

@Zli1893 Hey could you debug this? I got the exact same error for a batch_size greater than 1. I have written my own collate function. However that doesn't seem to be the problem.