Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
hieu.phan committed Mar 31, 2024
1 parent 5a7d821 commit 202e635
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 26 deletions.
6 changes: 3 additions & 3 deletions Zero-shot_classification/configs/chexray_mavl.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
test_file: '/data/data/xray14/test.csv'
test_file: '/data/VLM/data/xray14/test.csv'
disease_book: 'observation explanation.json'
concept_book: '../Pretrain/concept_gen/gpt4_mimic.json'

dataset: 'chexray'
root: '/data/data/xray14/cxr'
root: '/data/VLM/data/xray14/cxr'
model: mavl
model_path: '../checkpoints/checkpoint_full_40.pth'

Expand All @@ -21,4 +21,4 @@ H: 4
self_attention: True
text_encoder: 'emilyalsentzer/Bio_ClinicalBERT'
pretrained: True
mode: feature
mode: text
4 changes: 2 additions & 2 deletions Zero-shot_classification/configs/covid_mavl.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
test_file: '/data/data/covidx-cxr2/test_split.csv'
test_file: '/data/VLM/data/covidx-cxr2/test_split.csv'
disease_book: 'observation explanation.json'
concept_book: '../Pretrain/concept_gen/gpt4_mimic.json'

dataset: 'covid-cxr2'
root: '/data/data/covidx-cxr2/train'
root: '/data/VLM/data/covidx-cxr2/train'
model: 'mavl'
model_path: '../checkpoints/checkpoint_full_40.pth'

Expand Down
6 changes: 3 additions & 3 deletions Zero-shot_classification/configs/padchest_rare_mavl.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
test_file: '/data/data/PadChest/test.csv'
test_file: '/data/VLM/data/PadChest/test.csv'
disease_book: 'observation explanation_padchest_rare.json'
# concept_book: '../Pretrain/concept_gen/gpt4_mimic_padchest_rare.json'
concept_book: '../Pretrain/concept_gen/gpt4_mimic_padchest_rare.json'

dataset: 'padchest'
root: '/data/data/PadChest/'
root: '/data/VLM/data/PadChest/'
model: 'mavl'
model_path: '../checkpoints/checkpoint_full_40.pth'

Expand All @@ -22,5 +22,5 @@ H: 4
text_encoder: 'emilyalsentzer/Bio_ClinicalBERT'
self_attention: True
pretrained: True
mode: text
mode: feature
class: rare
6 changes: 2 additions & 4 deletions Zero-shot_classification/configs/padchest_seen_mavl.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
test_file: '/data/VLM/data/PadChest/test.csv'
disease_book: 'observation explanation_padchest_rare.json'
# concept_book: '../Pretrain/concept_gen/gpt4_mimic_padchest_rare.json'
concept_book: '../Pretrain/concept_gen/gpt4_mimic_padchest_rare.json'

dataset: 'padchest'
root: '/data/VLM/data/PadChest/'
model: 'mavl'
# model_path: '../checkpoints/checkpoint_short_37.pth'
model_path: '../../medslip/checkpoints/cl_global_1e-1_true/checkpoint_40.pth'
model_path: '../checkpoints/checkpoint_37.pth'


image_res: 224
test_batch_size: 512
test_batch_size: 1024

d_model: 256
base_model: 'resnet50'
Expand Down
6 changes: 3 additions & 3 deletions Zero-shot_classification/configs/padchest_unseen_mavl.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
test_file: '/data/data/PadChest/test.csv'
test_file: '/data/VLM/data/PadChest/test.csv'
disease_book: 'observation explanation_padchest_rare.json'
# concept_book: '../Pretrain/concept_gen/gpt4_mimic_padchest_rare.json'
concept_book: '../Pretrain/concept_gen/gpt4_mimic_padchest_rare.json'

dataset: 'padchest'
root: '/data/data/PadChest/'
root: '/data/VLM/data/PadChest/'
model: 'mavl'
model_path: '../checkpoints/checkpoint_full_40.pth'

Expand All @@ -22,5 +22,5 @@ H: 4
text_encoder: 'emilyalsentzer/Bio_ClinicalBERT'
self_attention: True
pretrained: True
mode: text
mode: feature
class: unseen
2 changes: 1 addition & 1 deletion Zero-shot_classification/configs/rsna_mavl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ concept_book: '../Pretrain/concept_gen/gpt4_mimic.json'
dataset: 'rsna'
root: '/data/VLM/data/rsna'
model: mavl
model_path: '../checkpoints/checkpoint_full_46.pth'
model_path: '../checkpoints/checkpoint_full_40.pth'


image_res: 224
Expand Down
4 changes: 2 additions & 2 deletions Zero-shot_classification/configs/siim_mavl.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
test_file: '/data/data/siimacr/test.csv'
test_file: '/data/VLM/data/siimacr/test.csv'
disease_book: 'observation explanation.json'
concept_book: '../Pretrain/concept_gen/gpt4_mimic.json'

dataset: 'siim'
root: '/data/data/siimacr'
root: '/data/VLM/data/siimacr'
model: mavl
model_path: '../checkpoints/checkpoint_full_40.pth'

Expand Down
7 changes: 0 additions & 7 deletions Zero-shot_classification/result_mavl_chexpert_feature.csv

This file was deleted.

22 changes: 22 additions & 0 deletions Zero-shot_classification/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ def get_tokenizer(tokenizer,target_text):

return target_tokenizer

def log_to_csv(filename, data, firstrow=None):
file_exists = os.path.isfile(filename)
with open(filename, 'a', newline='') as csvfile:
writer = csv.writer(csvfile)
if not file_exists:
# Write header if file doesn't exist
writer.writerow(firstrow) # Example header
writer.writerow(data)


def test(config):
device = accelerator.device
print("Total CUDA devices: ", torch.cuda.device_count())
Expand Down Expand Up @@ -452,7 +462,10 @@ def test(config):

# Write the data rows
csv_writer.writerows(table_data)
<<<<<<< HEAD

=======
>>>>>>> c7e9f45 (update result logs)
print(table)
log_csv = True
if log_csv:
Expand All @@ -466,12 +479,17 @@ def test(config):
header = ['Dataset', "Accuracy", "Max F1", "AUC ROC", "Precision", "Recall"]
log_to_csv(csv_filename, data, header)

<<<<<<< HEAD
# print('The average f1 is {F1_avg:.4f}'.format(F1_avg=f1_avg))
# print('The average ACC is {ACC_avg:.4f}'.format(ACC_avg=acc_avg))
# for i in range(len(target_class)):
# print('F1 of {} is {}'.format(target_class[i], max_f1s[i]))
# print('ACC of {} is {}'.format(target_class[i], accs[i]))

=======
# Print the table

>>>>>>> c7e9f45 (update result logs)

if __name__ == '__main__':
parser = argparse.ArgumentParser()
Expand All @@ -485,7 +503,11 @@ def test(config):
accelerator = Accelerator()
if args.model_path:
config['model_path'] = args.model_path
<<<<<<< HEAD

=======

>>>>>>> c7e9f45 (update result logs)
os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu
if args.gpu != '-1':
torch.cuda.current_device()
Expand Down
21 changes: 20 additions & 1 deletion Zero-shot_classification/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
filenames=(chexpert_mavl chexray_mavl covid_mavl rsna_mavl siim_mavl padchest_rare_mavl padchest_seen_mavl padchest_unseen_mavl)
ckpts=(25 28 31 34 37 state)
# model_name=output_masked_text5e-1
Expand All @@ -6,4 +7,22 @@ for filename in "${filenames[@]}"; do
for ckpt in "${ckpts[@]}"; do
CUDA_VISIBLE_DEVICES=0 python test.py --config configs/${filename}.yaml --model_path ../checkpoints/${model_name}/checkpoint_${ckpt}.pth
done
done
done
=======
# filenames=(chexpert_mavl chexray_mavl covid_mavl rsna_mavl siim_mavl padchest_rare_mavl padchest_seen_mavl padchest_unseen_mavl)
filenames=(padchest_unseen_mavl)
# model_name=output_masked_text5e-1
for filename in "${filenames[@]}"; do
CUDA_VISIBLE_DEVICES=0 python test.py --config configs/${filename}.yaml --model_path ../checkpoints/checkpoint_full_40.pth
done

for filename in "${filenames[@]}"; do
CUDA_VISIBLE_DEVICES=0 python test.py --config configs/${filename}.yaml --model_path ../checkpoints/checkpoint_full_46.pth
done

# for filename in "${filenames[@]}"; do
# CUDA_VISIBLE_DEVICES=0 python test.py --config configs/${filename}.yaml --model_path ../checkpoints/checkpoint_short_37.pth
# done


>>>>>>> c7e9f45 (update result logs)

0 comments on commit 202e635

Please sign in to comment.