assignment-a3: adds annotation visualization and document
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
from typing import List
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
|
||||
class AnnotationRect:
|
||||
@@ -36,3 +38,44 @@ def read_groundtruth_file(path: str) -> List[AnnotationRect]:
|
||||
return annotationRects
|
||||
|
||||
|
||||
def get_image_with_max_annotations(dir_path: str) -> str:
|
||||
img_pattern = re.compile(r'^(\d+)\.jpg$')
|
||||
files = set(os.listdir(dir_path))
|
||||
max_file = None
|
||||
max_annotations = 0
|
||||
|
||||
for fname in files:
|
||||
match = img_pattern.match(fname)
|
||||
if match:
|
||||
img_file = os.path.join(dir_path, fname)
|
||||
annotations_number = len(read_groundtruth_file(os.path.join(
|
||||
dir_path, f"{match.group(1)}.gt_data.txt")))
|
||||
if (annotations_number > max_annotations):
|
||||
max_file = img_file
|
||||
max_annotations = annotations_number
|
||||
return max_file
|
||||
|
||||
|
||||
def visualize_image(image_path: str, output_path='output.jpg', rect_color=(255, 0, 0), width=2):
|
||||
img_pattern = re.compile(r'(.*)(\.jpg)')
|
||||
match = img_pattern.match(image_path)
|
||||
annotations = read_groundtruth_file(f"{match.group(1)}.gt_data.txt")
|
||||
|
||||
img = Image.open(image_path).convert('RGB')
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
for annotation in annotations:
|
||||
draw.rectangle([annotation.x1, annotation.y1, annotation.x2, annotation.y2],
|
||||
outline=rect_color, width=width)
|
||||
|
||||
img.save(output_path)
|
||||
|
||||
|
||||
def main():
|
||||
image_file = get_image_with_max_annotations(
|
||||
"/home/ubuntu/mmp_wise2526_franksim/.data/mmp-public-3.2/train")
|
||||
visualize_image(image_file)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
BIN
mmp/a3/document.pdf
Normal file
BIN
mmp/a3/document.pdf
Normal file
Binary file not shown.
80
mmp/a3/document.tex
Normal file
80
mmp/a3/document.tex
Normal file
@@ -0,0 +1,80 @@
|
||||
\documentclass[11pt,a4paper]{article}
|
||||
|
||||
% Language and encoding settings
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage[english]{babel}
|
||||
|
||||
% Page formatting
|
||||
\usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
|
||||
\usepackage{setspace}
|
||||
\onehalfspacing
|
||||
|
||||
% Header/Footer
|
||||
\usepackage{fancyhdr}
|
||||
\pagestyle{fancy}
|
||||
\fancyhf{} % clear all header and footer fields
|
||||
\fancyhead[L]{\textbf{\course}}
|
||||
\fancyhead[C]{Assignment \assignmentnumber}
|
||||
\fancyhead[R]{\name}
|
||||
\fancyfoot[C]{\thepage}
|
||||
|
||||
% Other packages
|
||||
\usepackage{enumitem}
|
||||
\usepackage{graphicx}
|
||||
|
||||
% Custom commands for easy detail insertion
|
||||
\newcommand{\assignmentnumber}{03} % <-- CHANGE Assignment Number
|
||||
\newcommand{\name}{Simon Franken} % <-- CHANGE YOUR NAME
|
||||
\newcommand{\course}{Multimedia Project WiSe 2526} % <-- CHANGE COURSE NAME
|
||||
\newcommand{\duedate}{2025-11-05} % <-- CHANGE DUE DATE
|
||||
|
||||
% Title formatting
|
||||
\usepackage{titling}
|
||||
\pretitle{
|
||||
\vspace*{2cm}
|
||||
\begin{center}
|
||||
\LARGE\bfseries
|
||||
}
|
||||
\posttitle{\par\end{center}\vspace{1cm}}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\title{Assignment \assignmentnumber}
|
||||
\author{\name}
|
||||
\date{\duedate}
|
||||
|
||||
\maketitle
|
||||
|
||||
\begin{center}
|
||||
\textbf{Course:} \course
|
||||
\end{center}
|
||||
\vspace{0.5cm}
|
||||
|
||||
%------------------ START OF ASSIGNMENT -----------------------
|
||||
|
||||
% Write your solutions below
|
||||
|
||||
\section*{Exercise 3.1 Dataset Parsing}
|
||||
|
||||
\begin{enumerate}[label=\alph*)]
|
||||
\setcounter{enumi}{2}
|
||||
\item \begin{figure}[htp]
|
||||
\centering
|
||||
\includegraphics[width=4cm]{output.jpg}
|
||||
\caption{02254418.jpg with 18 annotations}
|
||||
\end{figure}
|
||||
\end{enumerate}
|
||||
|
||||
\section*{Exercise 3.3 Training}
|
||||
\begin{tabular}{|c||c|}
|
||||
\hline Batch size & 32 \\
|
||||
\hline Training epoches & 10 \\
|
||||
\hline Loss & 0.3719 \\
|
||||
\hline Accuracy & 78.90 \% \\
|
||||
\hline
|
||||
\end{tabular}
|
||||
|
||||
%------------------ END OF ASSIGNMENT -----------------------
|
||||
|
||||
\end{document}
|
||||
BIN
mmp/a3/output.jpg
Normal file
BIN
mmp/a3/output.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
Reference in New Issue
Block a user