truc-h-nguyen / Toddler-activity-suggestions

1 stars 0 forks source link

[notes] 11-7-2021 #8

Closed nickvazz closed 2 years ago

nickvazz commented 2 years ago

https://scikit-image.org/docs/stable/auto_examples/transform/plot_rescale.html

https://albumentations.ai

https://aditi-mittal.medium.com/introduction-to-u-net-and-res-net-for-image-segmentation-9afcb432ee2f

https://keras.io/examples/vision/retinanet/

https://towardsdatascience.com/master-the-coco-dataset-for-semantic-image-segmentation-part-1-of-2-732712631047

https://voxel51.com/docs/fiftyone/api/fiftyone.core.labels.htmlhighlight=bounding%20box#fiftyone.core.labels.Detection.bounding_box

https://voxel51.com/docs/fiftyone/recipes/image_deduplication.html?highlight=keras

https://towardsdatascience.com/an-overview-of-resnet-and-its-variants-5281e2f56035

https://keras.io/examples/vision/retinanet/#computing-pairwise-intersection-over-union-iou

https://github.com/matterport/Mask_RCNN

https://aditi-mittal.medium.com/introduction-to-u-net-and-res-net-for-image-segmentation-9afcb432ee2f

dataset = foz.load_zoo_dataset(
    "coco-2017",
    split="train",
    label_types=["segmentations"],
    classes=["bowl", "teddy bear"],
    max_samples=20,
)

sample = list(dataset)[0]

import numpy as np
import matplotlib.image as mpimg
import matplotlib.pyplot as plt

img = sample['filepath']
img = mpimg.imread(img)

useful_detections = [d for d in sample['ground_truth']['detections'] if d['label'] in ['teddy_bear','bowl']]

bbox = useful_detections[0]['bounding_box']
x,y,w,h = bbox

mask = np.zeros(img.shape[:2])
mask[int(y*img.shape[0]):int((y+h)*img.shape[0])+1, int(x*img.shape[1]):int((x+w)*img.shape[1])+1] += useful_detections[0]['mask']

fig, ax = plt.subplots(ncols=1, figsize=(15,10))
ax.imshow(img)
ax.imshow(mask, alpha=0.5,)
ax.scatter(img.shape[1] * np.array([x,x,x+w,x+w]), img.shape[0] * np.array([y,y+h,y,y+h]), color='r')
plt.show()
nickvazz commented 2 years ago

https://stackoverflow.com/questions/31877353/overlay-an-image-segmentation-with-numpy-and-matplotlib


fig, ax = plt.subplots(ncols=1, figsize=(15,10))
ax.imshow(img/256 + mask.reshape(mask.shape[0], mask.shape[1], 1).astype(float))
plt.show()
image
nickvazz commented 2 years ago

https://keras.io/examples/vision/oxford_pets_image_segmentation/

nickvazz commented 2 years ago

this is a way to iterate through the segmentations in the training loop

from tensorflow import keras
import numpy as np
from tensorflow.keras.preprocessing.image import load_img

class OxfordPets(keras.utils.Sequence):
    """Helper to iterate over the data (as Numpy arrays)."""

    def __init__(self, batch_size, img_size, input_img_paths, target_img_paths):
        self.batch_size = batch_size
        self.img_size = img_size
        self.input_img_paths = input_img_paths
        self.target_img_paths = target_img_paths

    def __len__(self):
        return len(self.target_img_paths) // self.batch_size

    def __getitem__(self, idx):
        """Returns tuple (input, target) correspond to batch #idx."""
        i = idx * self.batch_size
        batch_input_img_paths = self.input_img_paths[i : i + self.batch_size]
        batch_target_img_paths = self.target_img_paths[i : i + self.batch_size]
        x = np.zeros((self.batch_size,) + self.img_size + (3,), dtype="float32")
        for j, path in enumerate(batch_input_img_paths):
            img = load_img(path, target_size=self.img_size)
            x[j] = img
        y = np.zeros((self.batch_size,) + self.img_size + (1,), dtype="uint8")
        for j, path in enumerate(batch_target_img_paths):
            img = load_img(path, target_size=self.img_size, color_mode="grayscale")
            y[j] = np.expand_dims(img, 2)
            # Ground truth labels are 1, 2, 3. Subtract one to make them 0, 1, 2:
            y[j] -= 1
        return x, y