text stringlengths 0 4.99k |
|---|
ax[3].imshow(keras.preprocessing.image.array_to_img(inv3_kernel[0, ..., None])) |
ax[3].set_title(\"Involution Kernel 3\") |
png |
Conclusions |
In this example, the main focus was to build an Involution layer which can be easily reused. While our comparisons were based on a specific task, feel free to use the layer for different tasks and report your results. |
According to me, the key take-away of involution is its relationship with self-attention. The intuition behind location-specific and channel-spefic processing makes sense in a lot of tasks. |
Moving forward one can: |
Look at Yannick's video on involution for a better understanding. |
Experiment with the various hyperparameters of the involution layer. |
Build different models with the involution layer. |
Try building a different kernel generation method altogether. |
Training a keypoint detector with data augmentation and transfer learning. |
Keypoint detection consists of locating key object parts. For example, the key parts of our faces include nose tips, eyebrows, eye corners, and so on. These parts help to represent the underlying object in a feature-rich manner. Keypoint detection has applications that include pose estimation, face detection, etc. |
In this example, we will build a keypoint detector using the StanfordExtra dataset, using transfer learning. This example requires TensorFlow 2.4 or higher, as well as imgaug library, which can be installed using the following command: |
!pip install -q -U imgaug |
Data collection |
The StanfordExtra dataset contains 12,000 images of dogs together with keypoints and segmentation maps. It is developed from the Stanford dogs dataset. It can be downloaded with the command below: |
!wget -q http://vision.stanford.edu/aditya86/ImageNetDogs/images.tar |
Annotations are provided as a single JSON file in the StanfordExtra dataset and one needs to fill this form to get access to it. The authors explicitly instruct users not to share the JSON file, and this example respects this wish: you should obtain the JSON file yourself. |
The JSON file is expected to be locally available as stanfordextra_v12.zip. |
After the files are downloaded, we can extract the archives. |
!tar xf images.tar |
!unzip -qq ~/stanfordextra_v12.zip |
Imports |
from tensorflow.keras import layers |
from tensorflow import keras |
import tensorflow as tf |
from imgaug.augmentables.kps import KeypointsOnImage |
from imgaug.augmentables.kps import Keypoint |
import imgaug.augmenters as iaa |
from PIL import Image |
from sklearn.model_selection import train_test_split |
from matplotlib import pyplot as plt |
import pandas as pd |
import numpy as np |
import json |
import os |
Define hyperparameters |
IMG_SIZE = 224 |
BATCH_SIZE = 64 |
EPOCHS = 5 |
NUM_KEYPOINTS = 24 * 2 # 24 pairs each having x and y coordinates |
Load data |
The authors also provide a metadata file that specifies additional information about the keypoints, like color information, animal pose name, etc. We will load this file in a pandas dataframe to extract information for visualization purposes. |
IMG_DIR = \"Images\" |
JSON = \"StanfordExtra_V12/StanfordExtra_v12.json\" |
KEYPOINT_DEF = ( |
\"https://github.com/benjiebob/StanfordExtra/raw/master/keypoint_definitions.csv\" |
) |
# Load the ground-truth annotations. |
with open(JSON) as infile: |
json_data = json.load(infile) |
# Set up a dictionary, mapping all the ground-truth information |
# with respect to the path of the image. |
json_dict = {i[\"img_path\"]: i for i in json_data} |
A single entry of json_dict looks like the following: |
'n02085782-Japanese_spaniel/n02085782_2886.jpg': |
{'img_bbox': [205, 20, 116, 201], |
'img_height': 272, |
'img_path': 'n02085782-Japanese_spaniel/n02085782_2886.jpg', |
'img_width': 350, |
'is_multiple_dogs': False, |
'joints': [[108.66666666666667, 252.0, 1], |
[147.66666666666666, 229.0, 1], |
[163.5, 208.5, 1], |
[0, 0, 0], |
[0, 0, 0], |
[0, 0, 0], |
[54.0, 244.0, 1], |
[77.33333333333333, 225.33333333333334, 1], |
[79.0, 196.5, 1], |
[0, 0, 0], |
[0, 0, 0], |
[0, 0, 0], |
[0, 0, 0], |
[0, 0, 0], |
[150.66666666666666, 86.66666666666667, 1], |
[88.66666666666667, 73.0, 1], |
[116.0, 106.33333333333333, 1], |
[109.0, 123.33333333333333, 1], |
[0, 0, 0], |
[0, 0, 0], |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.