Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TFDSv4 carla_video_tracking upgrade. #1836

Merged
merged 47 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
de621f6
user init feature
davidslater Nov 29, 2022
5b70cec
update docs
davidslater Nov 29, 2022
58bec8d
update docs and error
davidslater Dec 2, 2022
1ba2c28
better metrics
davidslater Nov 16, 2022
02834e4
Adding initial files, ArmoryDataGenerator needs updated to include co…
jprokos26 Dec 19, 2022
61a487f
found an easy change to add custom metrics without having to worry as…
ppark-twosixtech Dec 5, 2022
4d8ac63
reverting changes to test loading custom metrics
ppark-twosixtech Dec 6, 2022
f8bc198
Merge pytorch, tf2, and carla mot images (#1786)
Dec 9, 2022
0b7ffa0
fix image link (#1817)
Dec 9, 2022
014e1fc
Adding context for Generators. Input shapes causing issue with metric…
jprokos26 Dec 20, 2022
d718e69
Adding unversioned files.
jprokos26 Dec 20, 2022
ef3b1f7
Separating dataloader batches into List[Dict[ndarray: (frames, coords…
jprokos26 Dec 20, 2022
2577998
Migrating carla_video_tracking_test and implementing preprocessing.
jprokos26 Dec 20, 2022
07741c5
adding carla_video_tracking_test checksum
jprokos26 Dec 20, 2022
631e25b
Adding carla_video_tracking_test cached dataset
jprokos26 Dec 20, 2022
5943015
removing carla_video_tracking_dev to readd as rename instead of new file
jprokos26 Dec 20, 2022
4ca907b
marking dev as rename
jprokos26 Dec 20, 2022
204097e
removing extraneous code
jprokos26 Dec 20, 2022
5757f0b
removing testing changes
jprokos26 Dec 20, 2022
53708ef
removing extraneous code
jprokos26 Dec 21, 2022
0bdb3ec
Addressing https://github.com/twosixlabs/armory/pull/1836#discussion_…
jprokos26 Dec 22, 2022
e198f81
Addressing https://github.com/twosixlabs/armory/pull/1836#discussion_…
jprokos26 Dec 22, 2022
d9c0a22
Condensing preprocessor code. Addresses https://github.com/twosixlabs…
jprokos26 Dec 22, 2022
d9862ce
Addressing https://github.com/twosixlabs/armory/pull/1836#discussion_…
jprokos26 Dec 22, 2022
f07ae03
Removing extra code added during rebase. Addresssing https://github.c…
jprokos26 Dec 22, 2022
9716c58
Addressing https://github.com/twosixlabs/armory/pull/1836#discussion_…
jprokos26 Dec 22, 2022
8db643f
Addresses https://github.com/twosixlabs/armory/pull/1836/files/f07ae0…
jprokos26 Dec 22, 2022
612fe1e
Suggestion from https://github.com/twosixlabs/armory/pull/1836#discus…
jprokos26 Dec 23, 2022
4837db0
Moving batch fixup to appropriate class. See https://github.com/twosi…
jprokos26 Dec 23, 2022
742d6cb
Merge commit '4837db0e3da65322ebc3624688d9b1140222bacf' into pr/jprok…
jprokos26 Dec 23, 2022
18ce134
Addressing https://github.com/twosixlabs/armory/pull/1836#discussion_…
jprokos26 Dec 23, 2022
9f71947
Addressing https://github.com/twosixlabs/armory/pull/1836#discussion_…
jprokos26 Dec 23, 2022
4a29dba
Simplifying the preprocessor
jprokos26 Dec 23, 2022
7c2da86
Revert "Simplifying the preprocessor"
jprokos26 Dec 23, 2022
3781ac3
Merge branch 'tfdsv4' into tfdsv4-carla-video-rebase
jprokos26 Dec 23, 2022
3ecba72
Addressing https://github.com/twosixlabs/armory/pull/1836#discussion_…
jprokos26 Dec 23, 2022
e466546
Addressing https://github.com/twosixlabs/armory/pull/1836#discussion_…
jprokos26 Dec 29, 2022
192311c
Addressing https://github.com/twosixlabs/armory/pull/1836#issuecommen…
jprokos26 Dec 29, 2022
a82f34f
Addressing https://github.com/twosixlabs/armory/pull/1836#discussion_…
jprokos26 Dec 29, 2022
4dcd2ca
Addressing https://github.com/twosixlabs/armory/pull/1836#discussion_…
jprokos26 Jan 23, 2023
800a88f
Error message clarification
jprokos26 Jan 23, 2023
2960b34
Moving dataset context object to be stored within dataset info metada…
jprokos26 Feb 8, 2023
d3a703c
black formatting
jprokos26 Feb 8, 2023
a6b4de4
Merge branch 'tfdsv4' into pr/jprokos26/1836
jprokos26 Feb 8, 2023
ae4baea
removing accidentally pushed files
jprokos26 Feb 8, 2023
82dab31
Merge branch 'tfdsv4' into tfdsv4-carla-video-rebase
jprokos26 Mar 15, 2023
5b2eb35
Readdressing https://github.com/twosixlabs/armory/pull/1836#discussio…
jprokos26 Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""carla_video_tracking_dev dataset."""

from .carla_video_tracking_dev import CarlaVideoTrackingDev
15 changes: 5 additions & 10 deletions ...a/adversarial/carla_video_tracking_dev.py → ..._tracking_dev/carla_video_tracking_dev.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import glob
import numpy as np
from PIL import Image
import tensorflow.compat.v1 as tf
import tensorflow as tf
import tensorflow_datasets as tfds

_DESCRIPTION = """
Expand All @@ -21,7 +21,7 @@
}
"""

_URLS = "https://armory-public-data.s3.us-east-2.amazonaws.com/carla/carla_video_tracking_dev_2.0.0.tar.gz"
_URL = "https://armory-public-data.s3.us-east-2.amazonaws.com/carla/carla_video_tracking_dev_2.0.0.tar.gz"


class CarlaVideoTrackingDev(tfds.core.GeneratorBasedBuilder):
Expand Down Expand Up @@ -70,14 +70,9 @@ def _info(self) -> tfds.core.DatasetInfo:

def _split_generators(self, dl_manager: tfds.download.DownloadManager):
"""Returns SplitGenerators."""
path = dl_manager.download_and_extract(_URLS)

return [
tfds.core.SplitGenerator(
name="dev",
gen_kwargs={"path": os.path.join(path, "dev")},
)
]
path = dl_manager.download_and_extract(_URL)

return {"dev": self._generate_examples(path / "dev")}

def _generate_examples(self, path):
"""Yields examples."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://armory-public-data.s3.us-east-2.amazonaws.com/carla/carla_video_tracking_dev_2.0.0.tar.gz 1278862237 8b23ca76bd9602a8e3ff4058335b7fb8ca665660a8a958852715e9a26ffbef20 carla_video_tracking_dev_2.0.0.tar.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""carla_video_tracking_test dataset."""

from .carla_video_tracking_test import CarlaVideoTrackingTest
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import glob
import numpy as np
from PIL import Image
import tensorflow.compat.v1 as tf
import tensorflow as tf
import tensorflow_datasets as tfds


Expand All @@ -22,7 +22,7 @@
}
"""

_URLS = "https://armory-public-data.s3.us-east-2.amazonaws.com/carla/carla_video_tracking_test_2.0.0.tar.gz"
_URL = "https://armory-public-data.s3.us-east-2.amazonaws.com/carla/carla_video_tracking_test_2.0.0.tar.gz"


class CarlaVideoTrackingTest(tfds.core.GeneratorBasedBuilder):
Expand Down Expand Up @@ -71,14 +71,8 @@ def _info(self) -> tfds.core.DatasetInfo:

def _split_generators(self, dl_manager: tfds.download.DownloadManager):
"""Returns SplitGenerators."""
path = dl_manager.download_and_extract(_URLS)

return [
tfds.core.SplitGenerator(
name="test",
gen_kwargs={"path": os.path.join(path, "test")},
)
]
path = dl_manager.download_and_extract(_URL)
return {"test": self._generate_examples(path / "test")}

def _generate_examples(self, path):
"""Yields examples."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://armory-public-data.s3.us-east-2.amazonaws.com/carla/carla_video_tracking_test_2.0.0.tar.gz 387465525 6bd09f5cf50c0e16f34b5054e9d77f95cb4491a373ecb842431cc58ae50b882e carla_video_tracking_test_2.0.0.tar.gz
1 change: 1 addition & 0 deletions armory/datasets/art_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class WrappedDataGenerator(DataGenerator):
def __init__(self, gen):
super().__init__(gen.size, gen.batch_size)
self._iterator = gen
self.context = gen.context

def __iter__(self):
return iter(self._iterator)
Expand Down
14 changes: 14 additions & 0 deletions armory/datasets/cached_datasets.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
"url": null,
"version": "1.0.0"
},
"carla_video_tracking_dev": {
"sha256": "958d470dcd394928050f4123a7af05b0e389ceeec6fa0a3261df55a65e553b69",
"size": 1281628036,
"subdir": "carla_video_tracking_dev/2.0.0",
"url": null,
"version": "2.0.0"
},
"carla_video_tracking_test": {
"sha256": "8c52281611807243cba425ad3a588f4abca40dfb2b3ab828b9ad8a5191a7df10",
"size": 388218968,
"subdir": "carla_video_tracking_test/2.0.0",
"url": null,
"version": "2.0.0"
},
"digit": {
"sha256": "805fb5e33caf2029e13f4146c9d06fdb437ac5b0f0aa9668e3201922b617c559",
"size": 8349857,
Expand Down
6 changes: 6 additions & 0 deletions armory/datasets/config_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from armory.datasets import load, preprocessing, generator, filtering
from armory.datasets.context import contexts


def load_dataset(
Expand All @@ -20,6 +21,7 @@ def load_dataset(
index=None,
class_ids=None,
drop_remainder=False,
context=None,
):
# All are keyword elements by design
if name is None:
Expand Down Expand Up @@ -64,6 +66,9 @@ def load_dataset(

shuffle_elements = shuffle_files

if context is None and name in contexts:
context = contexts[name]

return generator.ArmoryDataGenerator(
info,
ds_dict,
Expand All @@ -78,4 +83,5 @@ def load_dataset(
element_map=preprocessing_fn,
shuffle_elements=shuffle_elements,
key_map=None,
context=context,
)
16 changes: 16 additions & 0 deletions armory/datasets/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import tensorflow as tf


class VideoContext:
def __init__(self, x_shape, frame_rate):
self.x_shape = x_shape
self.input_type = tf.uint8
self.frame_rate = frame_rate


carla_video_tracking_context = VideoContext(x_shape=(None, 960, 1280, 3), frame_rate=10)

contexts = {
"carla_video_tracking_dev": carla_video_tracking_context,
"carla_video_tracking_test": carla_video_tracking_context,
}
3 changes: 3 additions & 0 deletions armory/datasets/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ArmoryDataGenerator:
element_filter - predicate of which elements to keep; occurs prior to mapping
Note: size computations will be wrong when filtering is applied
element_map - function that takes a dataset element (dict) and maps to new element
context - context object
"""

FRAMEWORKS = ("tf", "numpy", "torch")
Expand All @@ -58,6 +59,7 @@ def __init__(
element_filter: callable = None,
element_map: callable = None,
key_map=None,
context=None,
):
if split not in info.splits:
raise ValueError(f"split {split} not in info.splits {list(info.splits)}")
Expand Down Expand Up @@ -141,6 +143,7 @@ def __init__(
shuffle_elements=shuffle_elements,
element_filter=element_filter,
element_map=element_map,
context=context,
)

def _set_params(self, **kwargs):
Expand Down
34 changes: 34 additions & 0 deletions armory/datasets/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,40 @@ def carla_over_obj_det_dev(element, modality="rgb"):
)


def carla_video_tracking_preprocess(x, y, y_patch_metadata, max_frames=None):
# Clip
if max_frames:
max_frames = int(max_frames)
if max_frames <= 0:
raise ValueError(f"max_frames {max_frames} must be > 0")
x = x[:max_frames, :]
y = y[:max_frames, :]
y_patch_metadata = {k: v[:max_frames, :] for (k, v) in y_patch_metadata.items()}
# Update labels
box_array = tf.squeeze(y, axis=0) if y.shape[0] == 1 else y
y = {"boxes": box_array}
y_patch_metadata = {
k: (tf.squeeze(v, axis=0) if v.shape[0] == 1 else v)
for k, v in y_patch_metadata.items()
}
return x, (y, y_patch_metadata)


@register
def carla_video_tracking_dev(element, max_frames=None):
return carla_video_tracking_preprocess(
element["video"],
element["bboxes"],
element["patch_metadata"],
max_frames=max_frames,
)


@register
def carla_video_tracking_test(element, max_frames=None):
return carla_video_tracking_dev(element, max_frames)


@register
def xview(element):
return image_to_canon(element["image"]), convert_tf_obj_det_label_to_pytorch(
Expand Down
2 changes: 1 addition & 1 deletion armory/metrics/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def _check_video_tracking_input(y, y_pred):
y_pred (List[Dict, ...]): same as above
"""
for input in [y, y_pred]:
assert isinstance(input, list)
assert isinstance(input, list), f"Expected List[Dict, ...] got {type(input)}"
for input_dict_i in input:
assert isinstance(input_dict_i, dict)
assert "boxes" in input_dict_i
Expand Down
3 changes: 3 additions & 0 deletions armory/scenarios/carla_video_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def load_test_dataset(self):
def next(self):
super().next()
self.y, self.y_patch_metadata = self.y
# Fix for tfdsv4 upgrade - separate batches into list
if isinstance(self.y, dict) and "boxes" in self.y:
self.y = [{"boxes": batch} for batch in self.y["boxes"]]
self.probe.update(y=self.y, y_patch_metadata=self.y_patch_metadata)

def run_benign(self):
Expand Down
2 changes: 1 addition & 1 deletion armory/utils/config_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from armory.art_experimental.attacks import patch
from armory.art_experimental.attacks.sweep import SweepAttack
from armory.data.datasets import ArmoryDataGenerator, EvalGenerator
from armory.datasets.generator import ArmoryDataGenerator
from armory.data.utils import maybe_download_weights_from_s3
from armory.utils import labels
import copy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"use_label": true
},
"dataset": {
"batch_size": 1,
"eval_split": "dev",
"framework": "numpy",
"module": "armory.data.adversarial_datasets",
"name": "carla_video_tracking_dev"
"test": {
"batch_size": 1,
"split": "dev",
"name": "carla_video_tracking_dev"
}
},
"defense": {
"kwargs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"use_label": true
},
"dataset": {
"batch_size": 1,
"eval_split": "dev",
"framework": "numpy",
"module": "armory.data.adversarial_datasets",
"name": "carla_video_tracking_dev"
"test": {
"batch_size": 1,
"split": "dev",
"name": "carla_video_tracking_dev"
}
},
"defense": null,
"metric": {
Expand Down