Skip to content

Commit

Permalink
removing debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliotMaitre committed Mar 25, 2024
1 parent 3b6259d commit 5c00e07
Showing 1 changed file with 0 additions and 160 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@

from happypose.pose_estimators.cosypose.cosypose.config import LOCAL_DATA_DIR

"""
from .augmentations import (
CropResizeToAspectAugmentation,
PillowBlur,
PillowBrightness,
PillowColor,
PillowContrast,
PillowSharpness,
VOCBackgroundAugmentation,
to_torch_uint8,
)
"""

from happypose.toolbox.datasets.augmentations import (
CropResizeToAspectTransform,
PillowBlur,
Expand All @@ -33,7 +20,6 @@
# HappyPose
from happypose.toolbox.datasets.scene_dataset import (
IterableSceneDataset,
ObjectData,
SceneDataset,
SceneObservation,
)
Expand All @@ -43,26 +29,9 @@
)

from happypose.toolbox.datasets.scene_dataset_wrappers import remove_invisible_objects
# from happypose.toolbox.datasets.scene_dataset_wrappers import VisibilityWrapper
"""
from .augmentations import (
CropResizeToAspectAugmentation,
PillowBlur,
PillowBrightness,
PillowColor,
PillowContrast,
PillowSharpness,
VOCBackgroundAugmentation,
to_torch_uint8,
)
from .wrappers.visibility_wrapper import VisibilityWrapper
"""

def collate_fn(batch):
print("inside collate fn")
rgbs, targets = zip(*batch)
print("rgbs = ", rgbs)
print("targets =", targets)
# Stack the rgbs and convert to a tensor
rgbs = torch.stack(rgbs, dim=0)

Expand Down Expand Up @@ -175,25 +144,7 @@ def __init__(

self.label_to_category_id = label_to_category_id
self.min_area = min_area
"""
def collate_fn(self, list_data: List[DetectionData]) -> BatchDetectionData:
batch_data = BatchDetectionData(
rgbs=torch.from_numpy(np.stack([d.rgb for d in list_data])).permute(
0,
3,
1,
2,
),
bboxes=torch.from_numpy(np.stack([d.bboxes for d in list_data])),
labels=torch.from_numpy(np.stack([d.labels for d in list_data])),
masks=torch.from_numpy(np.stack([d.masks for d in list_data])),
#image_id=torch.from_numpy(np.stack([d.image_id for d in list_data])),
area=torch.from_numpy(np.stack([d.area for d in list_data])),
iscrowd=torch.from_numpy(np.stack([d.iscrowd for d in list_data]))
)

return batch_data
"""
def make_data_from_obs(self, obs: SceneObservation, idx):

obs = remove_invisible_objects(obs)
Expand Down Expand Up @@ -261,8 +212,6 @@ def make_data_from_obs(self, obs: SceneObservation, idx):

return rgb, target



def __getitem__(self, index: int):
assert isinstance(self.scene_ds, SceneDataset)
obs = self.scene_ds[index]
Expand All @@ -285,112 +234,3 @@ def __iter__(self):
iterator = iter(self.scene_ds)
while True:
yield self.find_valid_data(iterator)





def __init___old(
self,
scene_ds,
label_to_category_id,
min_area=50,
resize=(640, 480),
gray_augmentation=False,
rgb_augmentation=False,
background_augmentation=False,
):
self.scene_ds = scene_ds

self.resize_augmentation = CropResizeToAspectAugmentation(resize=resize)

self.background_augmentation = background_augmentation
self.background_augmentations = VOCBackgroundAugmentation(
voc_root=LOCAL_DATA_DIR,
p=0.3,
)

self.rgb_augmentation = rgb_augmentation
self.rgb_augmentations = [
PillowBlur(p=0.4, factor_interval=(1, 3)),
PillowSharpness(p=0.3, factor_interval=(0.0, 50.0)),
PillowContrast(p=0.3, factor_interval=(0.2, 50.0)),
PillowBrightness(p=0.5, factor_interval=(0.1, 6.0)),
PillowColor(p=0.3, factor_interval=(0.0, 20.0)),
]

self.label_to_category_id = label_to_category_id
self.min_area = min_area



def get_data_old(self, idx):

print("I am in get_data")
rgb, mask, state = self.scene_ds[idx]

rgb, mask, state = self.resize_augmentation(rgb, mask, state)

if self.background_augmentation:
rgb, mask, state = self.background_augmentations(rgb, mask, state)

if self.rgb_augmentation and random.random() < 0.8:
for augmentation in self.rgb_augmentations:
rgb, mask, state = augmentation(rgb, mask, state)

rgb, mask = to_torch_uint8(rgb), to_torch_uint8(mask)

categories = torch.tensor(
[self.label_to_category_id[obj["name"]] for obj in state["objects"]],
)
obj_ids = np.array([obj["id_in_segm"] for obj in state["objects"]])
boxes = np.array(
[torch.as_tensor(obj["bbox"]).tolist() for obj in state["objects"]],
)
boxes = torch.as_tensor(boxes, dtype=torch.float32).view(-1, 4)
area = torch.as_tensor(
(boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0]),
)
mask = np.array(mask)
masks = mask == obj_ids[:, None, None]
masks = torch.as_tensor(masks)

keep = area > self.min_area
boxes = boxes[keep]
area = area[keep]
categories = categories[keep]
masks = masks[keep, :, :]
num_objs = len(keep)

num_objs = len(obj_ids)
area = torch.as_tensor(area)
boxes = torch.as_tensor(boxes)
masks = torch.as_tensor(masks, dtype=torch.uint8)
image_id = torch.tensor([idx])
iscrowd = torch.zeros((num_objs), dtype=torch.int64)

target = {}
target["boxes"] = boxes
target["labels"] = categories
target["masks"] = masks
target["image_id"] = image_id
target["area"] = area
target["iscrowd"] = iscrowd
return rgb, target

def __getitem__old(self, index):
try_index = index
valid = False
n_attempts = 0
while not valid:
print("valid =", valid)
if n_attempts > 10:
msg = "Cannot find valid image in the dataset"
raise ValueError(msg)
im, target = self.get_data(try_index)
valid = len(target["boxes"]) > 0
if not valid:
try_index = random.randint(0, len(self.scene_ds) - 1)
n_attempts += 1
return im, target

0 comments on commit 5c00e07

Please sign in to comment.