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

ZeroDivisionError while running train.py #7

Open
TuhinKundu opened this issue Dec 28, 2018 · 3 comments
Open

ZeroDivisionError while running train.py #7

TuhinKundu opened this issue Dec 28, 2018 · 3 comments
Labels
question Further information is requested

Comments

@TuhinKundu
Copy link

Have setup the repository on Google Colab and uploaded train, test and validation (of 100 random images from train set) and tried running train.py which resulted in the following error. Any help?

------------ Options -------------
batch_size: 64
beta1: 0.9
beta2: 0.999
channels: 1
checkpoints_path: ./checkpoints
cuda: True
dataset_path: ./dataset
debug: False
ensemble: 1
epochs: 30
gpu_ids: 0
log_interval: 50
lr: 0.001
network: 0
no_cuda: False
patch_stride: 256
seed: 1
test_batch_size: 64
testset_path:
-------------- End ----------------

Loading "patch-wise" model...
Start training patch-wise network: 2018/12/28 16:59

/content/ICIAR2018/src/datasets.py:28: RuntimeWarning: invalid value encountered in long_scalars
self.augment_size = np.prod(self.shape) / len(labels)
Traceback (most recent call last):
File "train.py", line 14, in
pw_model.train()
File "/content/ICIAR2018/src/models.py", line 56, in train
best = self.validate(verbose=False)
File "/content/ICIAR2018/src/models.py", line 151, in validate
test_loss /= len(test_loader.dataset)
ZeroDivisionError: division by zero

@knazeri
Copy link
Member

knazeri commented Dec 29, 2018

@TuhinKundu The error happened during the validation process and it looks like that the length of the validation dataset is zero! Make sure your validation set is copied under /validation under your dataset path.

@knazeri knazeri added the question Further information is requested label Dec 29, 2018
@TuhinKundu
Copy link
Author

TuhinKundu commented Dec 29, 2018

@knazeri Thanks for responding! But I am definitely putting in a validation set comprising of 100 random images from the train set. Is the nomenclature of the validation set images to be maintained/changed to resolve the problem (as it may not be read by the program)? Because I did not change the names of the images while copying from the train set.

My validation set is currently like this:
!dir dataset/validation
b001.tif b016.tif is001.tif is016.tif iv001.tif iv016.tif n011.tif
b002.tif b017.tif is002.tif is017.tif iv002.tif iv017.tif n012.tif
b003.tif b018.tif is003.tif is018.tif iv003.tif iv018.tif n013.tif
b004.tif b019.tif is004.tif is019.tif iv004.tif iv019.tif n014.tif
b005.tif b020.tif is005.tif is020.tif iv005.tif iv020.tif n015.tif
b006.tif b091.tif is006.tif is091.tif iv006.tif n001.tif n016.tif
b007.tif b092.tif is007.tif is092.tif iv007.tif n002.tif n017.tif
b008.tif b093.tif is008.tif is093.tif iv008.tif n003.tif n018.tif
b009.tif b094.tif is009.tif is094.tif iv009.tif n004.tif n019.tif
b010.tif b095.tif is010.tif is095.tif iv010.tif n005.tif n020.tif
b011.tif b096.tif is011.tif is096.tif iv011.tif n006.tif
b012.tif b097.tif is012.tif is097.tif iv012.tif n007.tif
b013.tif b098.tif is013.tif is098.tif iv013.tif n008.tif
b014.tif b099.tif is014.tif is099.tif iv014.tif n009.tif
b015.tif b100.tif is015.tif is100.tif iv015.tif n010.tif

@knazeri
Copy link
Member

knazeri commented Dec 29, 2018

@TuhinKundu Your validation set is fine, I guess the root of this problem might be this line:

labels = {name: index for index in range(len(LABELS)) for name in glob.glob(path + '/' + LABELS[index] + '/*.tif')}

We are using glob to load files from a local disk, I'm not exactly sure if that's the right way to load data on Google Colab. You can check this by printing the size of the data to the output: print(len(labels))

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

No branches or pull requests

2 participants