Skip to content

Commit

Permalink
reorder imports
Browse files Browse the repository at this point in the history
  • Loading branch information
am committed Oct 1, 2024
1 parent 6e71f3f commit 37f9231
Show file tree
Hide file tree
Showing 17 changed files with 140 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@
import argparse
import os
import warnings
from copy import deepcopy
from types import SimpleNamespace

from copy import deepcopy
from llava.conversation import conv_templates
from llava.mm_utils import get_model_name_from_path
from llava.model.builder import load_pretrained_model
from monai.bundle.config_parser import ConfigParser
from monai.utils import look_up_option

from prompts import has_placeholder, replace, templates

# from llava.eval.run_vila import eval_model
from run_vila import eval_model
from torchxray_cls import all_models, cls_models
from types import SimpleNamespace



cls = {1: "fracture", 2: "pneumothorax", 3: "lung opacity"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import argparse
import os
import warnings
from types import SimpleNamespace

from copy import deepcopy

from llava.conversation import conv_templates
Expand All @@ -23,10 +23,11 @@
from monai.utils import look_up_option

from prompts import has_placeholder, replace, templates

# from llava.eval.run_vila import eval_model
from run_vila import eval_model
from torchxray_cls import all_models, cls_models
from types import SimpleNamespace



cls = {1: "atelectasis", 2: "cardiomegaly", 3: "consolidation", 4: "edema", 5: "pleural effusion"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
import os
from types import SimpleNamespace

from run_vila import eval_model
# from llava.eval.run_vila import eval_model
from llava.mm_utils import get_model_name_from_path
from llava.model.builder import load_pretrained_model

from run_vila import eval_model

def batch_run(exp_id, mpath, conv_mode, folder_name):
prompt = (
Expand Down
6 changes: 3 additions & 3 deletions monai_vila2d/eval/scripts/classification/infer_chexpert.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
# load chest x-ray and try different classification prompts
import argparse
import os
from types import SimpleNamespace

from run_vila import eval_model
# from llava.eval.run_vila import eval_model
from llava.mm_utils import get_model_name_from_path
from llava.model.builder import load_pretrained_model

from run_vila import eval_model
from types import SimpleNamespace


def batch_run(exp_id, mpath, conv_mode, folder_name):
prompt = (
Expand Down
4 changes: 2 additions & 2 deletions monai_vila2d/eval/scripts/classification/metric_chexpert.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
# limitations under the License.

import argparse
import json
import numpy as np
import os
import re
import warnings

import numpy as np
from sklearn.metrics import f1_score
import json

classes = {"Atelectasis": "a", "Cardiomegaly": "b", "Consolidation": "c", "Edema": "d", "pleural_effusion": "e"}
gt_ids = {"Atelectasis": -6, "Cardiomegaly": -12, "Consolidation": -8, "Edema": -9, "pleural_effusion": -4}
Expand Down
5 changes: 3 additions & 2 deletions monai_vila2d/eval/scripts/classification/run_vila.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

import argparse
import os.path as osp
from io import BytesIO

import requests
import torch

from io import BytesIO

from llava.constants import DEFAULT_IMAGE_TOKEN, IMAGE_TOKEN_INDEX
from llava.conversation import SeparatorStyle, conv_templates
from llava.mm_utils import KeywordsStoppingCriteria, get_model_name_from_path, process_images, tokenizer_image_token
Expand Down
2 changes: 1 addition & 1 deletion monai_vila2d/eval/scripts/metric_pathvqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import json
import pickle
import argparse

def get_args():
parser = argparse.ArgumentParser()
Expand Down
3 changes: 2 additions & 1 deletion monai_vila2d/eval/scripts/metric_radvqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
# limitations under the License.


import argparse
import json
import jsonlines
import argparse


def get_args():
parser = argparse.ArgumentParser()
Expand Down
3 changes: 2 additions & 1 deletion monai_vila2d/eval/scripts/metric_slakevqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
# limitations under the License.


import argparse
import json
import jsonlines
import argparse


def get_args():
parser = argparse.ArgumentParser()
Expand Down
6 changes: 3 additions & 3 deletions monai_vila2d/eval/scripts/mimic_vqa/eval_pvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from pathlib import Path
import numpy as np

from glossary import normalize_word
from evaluate_metrics import calculate_f1score
from utils import load_json, load_jsonl
from glossary import normalize_word
from pathlib import Path
from scipy.stats import wilcoxon
from utils import load_json, load_jsonl

def get_significance(instruct, prediction1, prediction2):
gt = load_json(instruct)
Expand Down
2 changes: 1 addition & 1 deletion monai_vila2d/eval/scripts/mimic_vqa/evaluate_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# limitations under the License.

import math
from utils import *
from glossary import *
from utils import *

def bleu(candidate, references, n, weights):

Expand Down
9 changes: 3 additions & 6 deletions monai_vila2d/eval/scripts/mimic_vqa/metric_mimicvqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
# limitations under the License.


import os
import json
# import jsonlines
import argparse

from pathlib import Path
import json
import numpy as np

from glossary import normalize_word
from evaluate_metrics import calculate_f1score
from glossary import normalize_word
from pathlib import Path
from utils import load_json, load_jsonl


Expand Down
7 changes: 4 additions & 3 deletions monai_vila2d/eval/scripts/mimic_vqa/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
# limitations under the License.


from pathlib import Path
import json
from typing import Any, List, Tuple, Union, Optional
from collections import defaultdict
import math

from collections import defaultdict
from pathlib import Path
from typing import Any, List


def load_json(path: Path) -> Any:
"""
Expand Down
100 changes: 100 additions & 0 deletions monai_vila2d/eval/scripts/print_metrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import json
import os

def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("--input", type=str, default=True)
return parser.parse_args()

def load_json(file_path):
with open(file_path, 'r') as f:
return json.load(f)


def main():

args = get_args()
results = {}


try:
json_data = load_json(os.path.join(args.input, 'radvqa/results.json'))
results['radvqa'] = json_data['accuracy']
except:
results['radvqa'] = '?'

try:
json_data = load_json(os.path.join(args.input, 'mimicvqa/results.json'))
results['mimicvqa'] = json_data['wavg_closed']
except:
results['mimicvqa'] = '?'

try:
json_data = load_json(os.path.join(args.input, 'slakevqa/results.json'))
results['slakevqa'] = json_data['accuracy']
except:
results['slakevqa'] = '?'

try:
json_data = load_json(os.path.join(args.input, 'pathvqa/results.json'))
results['pathvqa'] = json_data['accuracy']
except:
results['pathvqa'] = '?'


try:
json_data = load_json(os.path.join(args.input, 'report_mimiccxr/results.json'))
results['report_mimiccxr_bleu4'] = json_data['accuracy']['Bleu_4']
results['report_mimiccxr_rougel'] = json_data['accuracy']['ROUGE_L']

except:
results['report_mimiccxr_bleu4'] = '?'
results['report_mimiccxr_rougel'] = '?'


try:
json_data = load_json(os.path.join(args.input, 'chestxray14_class/results.json'))
results['chestxray14_class'] = json_data['f1']
except:
results['chestxray14_class'] = '?'


try:
json_data = load_json(os.path.join(args.input, 'chexpert_class/results.json'))
results['chexpert_class'] = json_data['f1']
except:
results['chexpert_class'] = '?'

try:
json_data = load_json(os.path.join(args.input, 'chestxray14_expert_class/results.json'))
results['chestxray14_expert_class'] = json_data['f1']
except:
results['chestxray14_expert_class'] = '?'

try:
json_data = load_json(os.path.join(args.input, 'chexpert_expert_class/results.json'))
results['chexpert_expert_class'] = json_data['f1']
except:
results['chexpert_expert_class'] = '?'

results = json.loads(json.dumps(results), parse_float=lambda x: round(100*float(x), 2)) # convert to percentage

print(json.dumps(results, indent = 4))
print([v for _, v in results.items()])

if __name__ == "__main__":
main()


3 changes: 1 addition & 2 deletions monai_vila2d/eval/scripts/report/compute_metrics_caption.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
# limitations under the License.

import argparse
import os
import json
import sys
import os
from pycocotools.coco import COCO
from pycocoevalcap.eval import COCOEvalCap

Expand Down
6 changes: 2 additions & 4 deletions monai_vila2d/eval/scripts/report/eval.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
__author__ = "tylin"
# Copyright (c) MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -10,12 +9,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .tokenizer.ptbtokenizer import PTBTokenizer
from .bleu.bleu import Bleu
from .cider.cider import Cider
from .meteor.meteor import Meteor
from .rouge.rouge import Rouge
from .cider.cider import Cider

from .tokenizer.ptbtokenizer import PTBTokenizer

class COCOEvalCap:
def __init__(self, coco, cocoRes):
Expand Down
9 changes: 4 additions & 5 deletions monai_vila2d/eval/scripts/report/report_mimiccxr_infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@
# limitations under the License.

import argparse
import re
from io import BytesIO
import os
import os.path as osp

import re
import requests
import torch
from PIL import Image

from io import BytesIO

from llava.constants import (
DEFAULT_IM_END_TOKEN,
Expand All @@ -36,6 +34,7 @@
from llava.model.builder import load_pretrained_model
from llava.utils import disable_torch_init

from PIL import Image

def load_filenames(file_path):
with open(file_path, "r") as f:
Expand Down

0 comments on commit 37f9231

Please sign in to comment.