Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'torchnet' #5

Open
calm-focus opened this issue Jun 14, 2018 · 15 comments
Open

ModuleNotFoundError: No module named 'torchnet' #5

calm-focus opened this issue Jun 14, 2018 · 15 comments

Comments

@calm-focus
Copy link

calm-focus commented Jun 14, 2018

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
Copy link
Author

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

@pyaf
Copy link
Owner

pyaf commented Jun 15, 2018

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
Copy link
Owner

pyaf commented Jun 15, 2018

Let me know if you still face any error.

@pyaf pyaf closed this as completed Jun 15, 2018
@calm-focus
Copy link
Author

@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

@pyaf pyaf reopened this Jun 15, 2018
@calm-focus
Copy link
Author

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
Copy link
Owner

pyaf commented Jun 15, 2018

do some debugging, let me know the cause.

@pyaf
Copy link
Owner

pyaf commented Jun 19, 2018

Hey, did you find the bug?

@calm-focus
Copy link
Author

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

@NazarovAV
Copy link

NazarovAV commented Jul 18, 2018

@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
Copy link

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
Copy link
Owner

pyaf commented Sep 5, 2018

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

@John1231983
Copy link

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
Copy link
Owner

pyaf commented Sep 6, 2018

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

@pbou
Copy link

pbou commented Oct 17, 2018

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants