muhammedtalo / COVID-19

Automated Detection of COVID-19 Cases Using Deep Neural Networks with X-Ray Images
120 stars 108 forks source link

Code not working/Incomplete code #3

Closed sri-harsh closed 3 years ago

sri-harsh commented 3 years ago

Code not working/Incomplete code for binary classes for covid detection.

The kfold is not done in the code and moreover not able to run the code despite adding.

Changing the code to bug free and complete version would be helpful!

muhammedtalo commented 3 years ago

Please take a look at Issue 2 (3 classes). "yaelbeng" user is able to run the code too.

sri-harsh commented 3 years ago

Did not work for me, can you please help. Encountering so many errors.

muhammedtalo commented 3 years ago

Please make sure that you are using "fastai" (v1) and use the code as it is given.

muhammedtalo commented 3 years ago

After that if it still does not work share the errors with your code.

sri-harsh commented 3 years ago

After that if it still does not work share the errors with your code.

Yeah, using the right version of fast.ai, the problem is with the dataset I presume. Please do guide me.

muhammedtalo commented 3 years ago

I would like to see inside your valid folder

sri-harsh commented 3 years ago

Not able to follow can you please explain once again, I am working on the binary class one right now not the three classes one.

sri-harsh commented 3 years ago

You mean along with the x-ray images in train and valid folders should we have those folders as well?

muhammedtalo commented 3 years ago

Your folder structure should be

X-ray Imagedataset

   Train
        Covid-19/images
        Pneumonia/images
        No_finding/images

Basically, place all three class folders inside Train folder

sri-harsh commented 3 years ago

Still the same error

muhammedtalo commented 3 years ago

There is no Valid set. You should have just the Train folder.

path='..... Dataset'/'Train' data = (ImageItemList.from_folder(path) .random_split_by_pct() .label_from_folder() .transform(tfms, size=224) .databunch())

muhammedtalo commented 3 years ago

Is it work? if not, show the error.

muhammedtalo commented 3 years ago

Try this one path='..... Dataset' (without Train)

data = ImageDataBunch.from_folder(path, train="Train", valid_pct =0.2, ds_tfms=get_transforms(), size=(256,256), bs=32, num_workers=4).normalize()

muhammedtalo commented 3 years ago

Did it work?

muhammedtalo commented 3 years ago

Sorry, I could not understand the error. You may google it. Also take a look at https://forums.fast.ai/t/not-working-data-imagedatabunch-from-folder-path-ds-tfms-tfms-size-224/30510

sri-harsh commented 3 years ago

Can you share the most recent working copy of the code you have please?

muhammedtalo commented 3 years ago

The code we have shared is the most recent one. See it worked over there. All the epochs and results

sri-harsh commented 3 years ago

Ok, thank you for your time. Means a lot!

muhammedtalo commented 3 years ago

You can also try fastai-v2 which is current version. But you should update the code (https://docs.fast.ai/tutorial.vision.html) Please let me know if that works?

sri-harsh commented 3 years ago

Yeah, I will check it out. Thanks for the suggestion!

muhammedtalo commented 3 years ago

In v2 colab

!pip install -Uqq fastbook import fastbook fastbook.setup_book()

from fastbook import *

from fastai.vision.all import * path = Path('/content/gdrive/My Drive/.../') train_fnames = get_image_files(path/"Train")

dblock = DataBlock(blocks=(ImageBlock(cls=PILImage), CategoryBlock), splitter=RandomSplitter(valid_pct=0.2, seed=23), get_y=parent_label, item_tfms=Resize(512, method="squish"), batch_tfms=None, )

dls = dblock.dataloaders(train_fnames)

train_df = len(train_fnames) print(f"There are {train_df} images")

print class names, number of class, length of train dataset, and length of valid dataset

dls.c, len(dls.train_ds), len(dls.valid_ds)

dls.show_batch()

....

muhammedtalo commented 3 years ago

Please let me know it works. I would like to further help if needed.

sri-harsh commented 3 years ago

Ok, I am trying it out. Will let you know.

sri-harsh commented 3 years ago

Getting the below error

image

muhammedtalo commented 3 years ago

path should contain your file directory For example, path = Path('/content/gdrive/My Drive/X-ray Image Dataset/')

muhammedtalo commented 3 years ago

Does it work?

muhammedtalo commented 3 years ago

Inside Train folder you sould have three folders (Covid/Pno/No_f)

sri-harsh commented 3 years ago

Yes, they are there, still the same problem, I have deleted all the files and re-uploaded and checked as well.

muhammedtalo commented 3 years ago

print train_fnames and let me see

sri-harsh commented 3 years ago

image

Here...it is empty.

muhammedtalo commented 3 years ago

it should contain folders should not be emty.

sri-harsh commented 3 years ago

Yeah in the drive folders are there but it is showing empty.

muhammedtalo commented 3 years ago

For example, I have different problem and here is folders b

muhammedtalo commented 3 years ago

e

My drive structure for two classes

muhammedtalo commented 3 years ago

?

sri-harsh commented 3 years ago

The same problem persists to be there.

muhammedtalo commented 3 years ago

I hope you can solve it. Please let me know once you have it.

Best

muhammedtalo commented 3 years ago

I will provide a new repo for the above problem [Kidney stone detection] (hopefully) this week. You can also check that one.

sri-harsh commented 3 years ago

image

Is it conv_block? Because there is no definition for conv_layer.

muhammedtalo commented 3 years ago

Check the new name for "conv_layer " in fastai -v2 from https://docs.fast.ai/ Please take a look at following tutorials: https://walkwithfastai.com/Introduction Here is link how to apply 5-fold cross validation: https://walkwithfastai.com/Cross_Validation Best,

muhammedtalo commented 3 years ago

The conv_layer in v1 have been named as conv2 in v2. conv2(256,2)

muhammedtalo commented 3 years ago

Please let us know once you run the code.

sri-harsh commented 3 years ago

conv2(256,2) is not working for me. ConvLayer(256, 2) is working. But still facing the below issue. image

muhammedtalo commented 3 years ago

https://discuss.pytorch.org/t/runtimeerror-mat1-and-mat2-shapes-cannot-be-multiplied-64x13056-and-153600x2048/101315

muhammedtalo commented 3 years ago

If you have 3 folders your model output must be 3.

muhammedtalo commented 3 years ago

See: https://github.com/muhammedtalo/COVID-19/blob/master/DarkCovidNet%20model%20for%20three%20classes.ipynb

sri-harsh commented 3 years ago

https://discuss.pytorch.org/t/runtimeerror-mat1-and-mat2-shapes-cannot-be-multiplied-64x13056-and-153600x2048/101315

Yeah changed linear related to filters to 1323.

muhammedtalo commented 3 years ago

Perfect it is working now!. For different "lr "you can look at https://docs.fast.ai/callback.schedule.html#LRFinder and search the main website https://docs.fast.ai/ Good luck!

sri-harsh commented 3 years ago

The way you used max_lr image

I removed max_lor image

Is this fine? This is the first time I am using fast.ai, I googled regarding this, did not properly get it.

muhammedtalo commented 3 years ago

It is OK you can use without max. In the v1: https://forums.fast.ai/t/question-on-default-layer-learning-rates-and-fit-one-cycle/50950