2
setup.py
2
setup.py
@ -39,7 +39,7 @@ setup(
|
|||||||
},
|
},
|
||||||
python_requires="~=3.6",
|
python_requires="~=3.6",
|
||||||
install_requires=["tensorflow-gpu", "Pillow", "h5py", "numpy", "opencv-python", "scikit-learn", "tqdm",
|
install_requires=["tensorflow-gpu", "Pillow", "h5py", "numpy", "opencv-python", "scikit-learn", "tqdm",
|
||||||
"beautifulsoup4", "matplotlib", "protobuf", "imutils"],
|
"beautifulsoup4", "matplotlib", "protobuf", "imutils", "matplotlib"],
|
||||||
license="Apache License 2.0",
|
license="Apache License 2.0",
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Operating System :: OS Independent",
|
"Operating System :: OS Independent",
|
||||||
|
|||||||
@ -346,3 +346,57 @@ def prepare(args: argparse.Namespace) -> None:
|
|||||||
pickle.dump(file_names_instances, file)
|
pickle.dump(file_names_instances, file)
|
||||||
with open(f"{args.ground_truth_path}/instances.bin", "wb") as file:
|
with open(f"{args.ground_truth_path}/instances.bin", "wb") as file:
|
||||||
pickle.dump(instances, file)
|
pickle.dump(instances, file)
|
||||||
|
|
||||||
|
|
||||||
|
def visualise(args: argparse.Namespace) -> None:
|
||||||
|
import pickle
|
||||||
|
|
||||||
|
from matplotlib import pyplot
|
||||||
|
import numpy as np
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
from twomartens.masterthesis.ssd_keras.eval_utils import coco_utils
|
||||||
|
|
||||||
|
with open(f"{args.ground_truth_path}/photo_paths.bin", "rb") as file:
|
||||||
|
file_names = pickle.load(file)
|
||||||
|
with open(f"{args.ground_truth_path}/instances.bin", "rb") as file:
|
||||||
|
instances = pickle.load(file)
|
||||||
|
|
||||||
|
output_path = f"{args.output_path}/visualise/{args.trajectory}"
|
||||||
|
annotation_file_train = f"{args.coco_path}/annotations/instances_train2014.json"
|
||||||
|
_, _, cats_to_names, _ = coco_utils.get_coco_category_maps(annotation_file_train)
|
||||||
|
|
||||||
|
colors = pyplot.cm.hsv(np.linspace(0, 1, 81)).tolist()
|
||||||
|
classes = ['background'].extend(cats_to_names)
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
nr_images = len(file_names[args.trajectory])
|
||||||
|
nr_digits = math.ceil(math.log10(nr_images))
|
||||||
|
for file_name, labels in zip(file_names[args.trajectory], instances[args.trajectory]):
|
||||||
|
if not labels:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# only loop through selected trajectory
|
||||||
|
with Image.open(file_name) as image:
|
||||||
|
figure = pyplot.figure(figsize=(20, 12))
|
||||||
|
pyplot.imshow(image)
|
||||||
|
|
||||||
|
current_axis = pyplot.gca()
|
||||||
|
|
||||||
|
for instance in labels:
|
||||||
|
bbox = instance['bbox']
|
||||||
|
# Transform the predicted bounding boxes for the 300x300 image to the original image dimensions.
|
||||||
|
xmin = bbox[0]
|
||||||
|
ymin = bbox[1]
|
||||||
|
xmax = bbox[2]
|
||||||
|
ymax = bbox[3]
|
||||||
|
color = colors[int(instance['coco_id'])]
|
||||||
|
label = f"{classes[int(instance['coco_id'])]}"
|
||||||
|
current_axis.add_patch(
|
||||||
|
pyplot.Rectangle((xmin, ymin), xmax - xmin, ymax - ymin, color=color, fill=False, linewidth=2))
|
||||||
|
current_axis.text(xmin, ymin, label, size='x-large', color='white',
|
||||||
|
bbox={'facecolor': color, 'alpha': 1.0})
|
||||||
|
pyplot.savefig(f"{output_path}/{str(i).zfill(nr_digits)}")
|
||||||
|
figure.clear()
|
||||||
|
|
||||||
|
i += 1
|
||||||
|
|||||||
@ -43,12 +43,14 @@ def main() -> None:
|
|||||||
train_parser = sub_parsers.add_parser("train", help="Train a network")
|
train_parser = sub_parsers.add_parser("train", help="Train a network")
|
||||||
evaluate_parser = sub_parsers.add_parser("evaluate", help="Evaluate a network")
|
evaluate_parser = sub_parsers.add_parser("evaluate", help="Evaluate a network")
|
||||||
test_parser = sub_parsers.add_parser("test", help="Test a network")
|
test_parser = sub_parsers.add_parser("test", help="Test a network")
|
||||||
|
visualise_parser = sub_parsers.add_parser("visualise", help="Visualise the ground truth")
|
||||||
|
|
||||||
# build sub parsers
|
# build sub parsers
|
||||||
_build_prepare(prepare_parser)
|
_build_prepare(prepare_parser)
|
||||||
_build_train(train_parser)
|
_build_train(train_parser)
|
||||||
_build_test(test_parser)
|
_build_test(test_parser)
|
||||||
_build_evaluate(evaluate_parser)
|
_build_evaluate(evaluate_parser)
|
||||||
|
_build_visualise(visualise_parser)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -60,6 +62,8 @@ def main() -> None:
|
|||||||
cli.test(args)
|
cli.test(args)
|
||||||
elif args.action == "prepare":
|
elif args.action == "prepare":
|
||||||
cli.prepare(args)
|
cli.prepare(args)
|
||||||
|
elif args.actions == "visualise":
|
||||||
|
cli.visualise(args)
|
||||||
|
|
||||||
|
|
||||||
def _build_prepare(parser: argparse.ArgumentParser) -> None:
|
def _build_prepare(parser: argparse.ArgumentParser) -> None:
|
||||||
@ -155,5 +159,12 @@ def _build_ssd_evaluate(parser: argparse.ArgumentParser) -> None:
|
|||||||
parser.add_argument("iteration", type=int, help="the validation iteration to use")
|
parser.add_argument("iteration", type=int, help="the validation iteration to use")
|
||||||
|
|
||||||
|
|
||||||
|
def _build_visualise(parser: argparse.ArgumentParser) -> None:
|
||||||
|
parser.add_argument("--coco_path", type=str, help="the path to the COCO data set")
|
||||||
|
parser.add_argument("--ground_truth_path", type=str, help="path to the prepared ground truth directory")
|
||||||
|
parser.add_argument("--output_path", type=str, help="path to the output directory")
|
||||||
|
parser.add_argument("trajectory", type=int, help="trajectory to visualise")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user