mahmoodlab / CLAM

Data-efficient and weakly supervised computational pathology on whole slide images - Nature Biomedical Engineering
http://clam.mahmoodlab.org
GNU General Public License v3.0
975 stars 329 forks source link

Issue running main.py #212

Closed suminwei closed 4 months ago

suminwei commented 8 months ago

Hi, I'm running into an issue while running main.py. When I run the following:

CUDA_VISIBLE_DEVICES=0 python main.py --drop_out --early_stopping --lr 2e-4 --k 10 --label_frac 0.75 --exp_code task_2_tumor_subtyping_CLAM_50 --weighted_sample --bag_loss ce --inst_loss svm --task task_2_tumor_subtyping --log_data --subtyping --data_root_dir DATA_ROOT_DIR --split_dir DATA_ROOT_DIR/splits/task_2_tumor_subtyping_75 I get the following error:

Init Loaders... Traceback (most recent call last): File "/n/data1/dfci/medicine/beltran/lab/lwei/Software/CLAM_install/CLAM/main_train_SARC_KICH.py", line 211, in <module> results = main(args) File "/n/data1/dfci/medicine/beltran/lab/lwei/Software/CLAM_install/CLAM/main_train_SARC_KICH.py", line 49, in main results, test_auc, val_auc, test_acc, val_acc = train(datasets, i, args) File "/n/data1/dfci/medicine/beltran/lab/lwei/Software/CLAM_install/CLAM/utils/core_utils.py", line 167, in train train_loader = get_split_loader(train_split, training=True, testing = args.testing, weighted = args.weighted_sample) File "/n/data1/dfci/medicine/beltran/lab/lwei/Software/CLAM_install/CLAM/utils/utils.py", line 59, in get_split_loader weights = make_weights_for_balanced_classes_split(split_dataset) File "/n/data1/dfci/medicine/beltran/lab/lwei/Software/CLAM_install/CLAM/utils/utils.py", line 149, in make_weights_for_balanced_classes_split weight_per_class = [N/len(dataset.slide_cls_ids[c]) for c in range(len(dataset.slide_cls_ids))] File "/n/data1/dfci/medicine/beltran/lab/lwei/Software/CLAM_install/CLAM/utils/utils.py", line 149, in <listcomp> weight_per_class = [N/len(dataset.slide_cls_ids[c]) for c in range(len(dataset.slide_cls_ids))] ZeroDivisionError: float division by zero

Would you know what might be causing this error? I have two classes of tumour subtypes. Thank you!

scjjb commented 7 months ago

It appears that not all of your classes are being represented in your dataset, check your dataset_csv file corresponds to the label_dict defined in main.py

suminwei commented 7 months ago

Thank you @scjjb, that was helpful! The classes were not defined the same way in my dataset_csv file and main.py. I fixed this and everything ran ok.