Commit ·
8bd97dc
1
Parent(s): fe6255d
Refactor submission_task1.py to include metric calculations and enhance output data structure; update pyproject.toml for improved dependency management.
Browse filesFiles changed (2)
4 unmodified lines56789101112131415161716 unmodified lines3435363738394041424344 unmodified lines8889909192939495969798991001014 unmodified linesimport jsonimport timefrom tqdm import tqdmval_dataset = load_dataset("SimulaMet-HOST/Kvasir-VQA")['raw'].select(range(5))predictions = [] # List to store predictionsgpu_name = torch.cuda.get_device_name(0) if torch.cuda.is_available() else "cpu"device = "CUDA" if torch.cuda.is_available() else "cpu"def get_mem(): return torch.cuda.memory_allocated(device) / \16 unmodified lines"Country": "Norway","Notes_to_organizers": '''eg, We have finetund XXX modelThis is optional . .Used data augmentations . .Custom info about the model . .Any insights. .+ Any informal things you like to share about this submission.'''}44 unmodified lines# Ensure all predictions match dataset lengthassert len(predictions) == len(val_dataset), "Mismatch between predictions and dataset length"# Saves predictions to a JSON filetotal_time, final_mem = round(time.time() - start_time, 4), round(get_mem() - post_model_mem, 2)model_mem_used = round(post_model_mem - initial_mem, 2)output_data = {"submission_info": SUBMISSION_INFO,"predictions": predictions, "total_time": total_time, "time_per_item": total_time / len(val_dataset),"memory_used_mb": final_mem, "model_memory_mb": model_mem_used, "gpu_name": gpu_name, }with open("predictions_1.json", "w") as f:4 unmodified lines5678910111213141516171819202122232425262716 unmodified lines4445464748495051525344 unmodified lines98991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401414 unmodified linesimport jsonimport timefrom tqdm import tqdmimport subprocessimport platformimport sysfrom evaluate import loadbleu = load("bleu")rouge = load("rouge")meteor = load("meteor")val_dataset = load_dataset("SimulaMet-HOST/Kvasir-VQA")['raw'].select(range(5))predictions = [] # List to store predictionsgpu_name = torch.cuda.get_device_name(0) if torch.cuda.is_available() else "cpu"device = "cuda" if torch.cuda.is_available() else "cpu"def get_mem(): return torch.cuda.memory_allocated(device) / \16 unmodified lines"Country": "Norway","Notes_to_organizers": '''eg, We have finetund XXX modelThis is optional . .Used data augmentations . .Custom info about the model . .Any insights. .+ Any informal things you like to share about this submission.'''}44 unmodified lines# Ensure all predictions match dataset lengthassert len(predictions) == len(val_dataset), "Mismatch between predictions and dataset length"total_time, final_mem = round(time.time() - start_time, 4), round(get_mem() - post_model_mem, 2)model_mem_used = round(post_model_mem - initial_mem, 2)# caulcualtes metricsreferences = [[e] for e in val_dataset['answer']]preds = [pred['answer'] for pred in predictions]bleu_result = bleu.compute(predictions=preds, references=references)rouge_result = rouge.compute(predictions=preds, references=references)meteor_result = meteor.compute(predictions=preds, references=references)bleu_score = bleu_result['bleu']rouge1_score = float(rouge_result['rouge1'])rouge2_score = float(rouge_result['rouge2'])rougeL_score = float(rouge_result['rougeL'])meteor_score = float(meteor_result['meteor'])public_scores = {'bleu': bleu_score,'rouge1': rouge1_score,'rouge2': rouge2_score,'rougeL': rougeL_score,'meteor': meteor_score}# Saves predictions to a JSON fileoutput_data = {"submission_info": SUBMISSION_INFO, "public_scores": public_scores,"predictions": predictions, "total_time": total_time, "time_per_item": total_time / len(val_dataset),"memory_used_mb": final_mem, "model_memory_mb": model_mem_used, "gpu_name": gpu_name,"debug": {"packages": json.loads(subprocess.check_output([sys.executable, "-m", "pip", "list", "--format=json"])),"system": {"python": platform.python_version(),"os": platform.system(),"platform": platform.platform(),"arch": platform.machine()}}}with open("predictions_1.json", "w") as f:
1234567891011121314151617181920212223242526272829[project]name = "medvqa"version = "0.14.8"description = "Competition Submission CLI for ImageCLEFmed-MedVQA-GI-2025 (https://github.com/simula/ImageCLEFmed-MEDVQA-GI-2025)"readme = "README.md"requires-python = ">=3.6"dependencies = ["huggingface_hub","huggingface_hub[hf_transfer]","gradio_client==1.3.0"]authors = [{ name="Sushant Gautam", email="sushant@simula.no" },]classifiers = ["Programming Language :: Python :: 3","Operating System :: OS Independent",]license = { text = "MIT" }[project.scripts]medvqa = "medvqa.cli:main"[tool.setuptools.packages.find]where = ["."]include = ["*", "competitions/**/"][project.urls]Homepage = "https://github.com/SushantGautam/MedVQA"12345678910111213141516171819202122232425262728293031[project]authors = [{name = "Sushant Gautam", email = "sushant@simula.no"},]classifiers = ["Programming Language :: Python :: 3","Operating System :: OS Independent",]dependencies = ["huggingface_hub","huggingface_hub[hf_transfer]","gradio_client==1.3.0","evaluate","rouge_score",]description = "Competition Submission CLI for ImageCLEFmed-MedVQA-GI-2025 (https://github.com/simula/ImageCLEFmed-MEDVQA-GI-2025)"license = {text = "MIT"}name = "medvqa"readme = "README.md"requires-python = ">=3.6"version = "0.14.8"[project.scripts]medvqa = "medvqa.cli:main"[tool.setuptools.packages.find]include = ["*", "competitions/**/"]where = ["."][project.urls]Homepage = "https://github.com/SushantGautam/MedVQA"
medvqa/submission_samples/gi-2025/submission_task1.py+47-7
pyproject.toml+17-15