DenseNet-MURA-PyTorch icon indicating copy to clipboard operation
DenseNet-MURA-PyTorch copied to clipboard

ModuleNotFoundError: No module named 'torchnet'

Open zli1893 opened this issue 7 years ago • 15 comments

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?

zli1893 avatar Jun 14 '18 02:06 zli1893

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

zli1893 avatar Jun 15 '18 07:06 zli1893

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 avatar Jun 15 '18 07:06 pyaf

Let me know if you still face any error.

pyaf avatar Jun 15 '18 07:06 pyaf

@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

zli1893 avatar Jun 15 '18 08:06 zli1893

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

zli1893 avatar Jun 15 '18 08:06 zli1893

do some debugging, let me know the cause.

pyaf avatar Jun 15 '18 08:06 pyaf

Hey, did you find the bug?

pyaf avatar Jun 19 '18 13:06 pyaf

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

zli1893 avatar Jun 25 '18 13:06 zli1893

@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

NazarovAV avatar Jul 18 '18 08:07 NazarovAV

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'

John1231983 avatar Sep 05 '18 05:09 John1231983

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

pyaf avatar Sep 05 '18 14:09 pyaf

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

John1231983 avatar Sep 05 '18 22:09 John1231983

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

pyaf avatar Sep 06 '18 03:09 pyaf

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

pbou avatar Oct 17 '18 00:10 pbou

@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.

rushin682 avatar Mar 27 '19 13:03 rushin682