Skip to content

Commit

Permalink
add changes to load wlasl100 dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlainesv committed Jun 29, 2023
1 parent 07e1470 commit c73db99
Show file tree
Hide file tree
Showing 7 changed files with 341 additions and 376 deletions.
5 changes: 3 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
MIN_INPUT_HEIGHT = 60
MAX_INPUT_HEIGHT = 60
AUTSL_INPUT_HEIGHT = 60
MEJIAPEREZ_INPUT_HEIGHT = 64
WLASL100_INPUT_HEIGHT = 64
RANDOM_SEED = 0
28 changes: 22 additions & 6 deletions dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import IntEnum
import tensorflow as tf
from config import MAX_INPUT_HEIGHT, MIN_INPUT_HEIGHT
from config import AUTSL_INPUT_HEIGHT, MEJIAPEREZ_INPUT_HEIGHT, WLASL100_INPUT_HEIGHT
from data_augmentation import RandomFlip, RandomScale, RandomShift, RandomRotation, RandomSpeed
from preprocessing import Center, CenterAtFirstFrame2D, FillBlueWithAngle, PadIfLessThan, RemoveZ, ResizeIfMoreThan, TranslationScaleInvariant
import tensorflow_datasets as tfds
Expand Down Expand Up @@ -51,15 +51,15 @@ class LayerType(IntEnum):
},
'train_resize': {
'type': LayerType.Normalization,
'layer': ResizeIfMoreThan(frames=MIN_INPUT_HEIGHT)
'layer': ResizeIfMoreThan(frames=100)
},
'test_resize': {
'type': LayerType.Normalization,
'layer': ResizeIfMoreThan(frames=MAX_INPUT_HEIGHT)
'layer': ResizeIfMoreThan(frames=100)
},
'pad': {
'type': LayerType.Normalization,
'layer': PadIfLessThan(frames=MIN_INPUT_HEIGHT)
'layer': PadIfLessThan(frames=100)
},
'angle': {
'type': LayerType.Data,
Expand Down Expand Up @@ -205,18 +205,34 @@ def label_to_one_hot(item):
# obtain characteristics of the dataset
num_train_examples = ds["train"].cardinality()
num_val_examples = ds["validation"].cardinality()
if "test" in ds.keys:
if "test" in ds.keys():
ds["test"] = ds["test"].map(label_to_one_hot)
num_test_examples = ds["test"].cardinality()
else:
num_test_examples = 0
num_total_examples = num_train_examples + num_val_examples + num_test_examples

if name == "autsl_tssi":
input_height = AUTSL_INPUT_HEIGHT
elif name == "mejiaperez_tssi":
input_height = MEJIAPEREZ_INPUT_HEIGHT
elif name == "wlasl100_tssi":
input_height = WLASL100_INPUT_HEIGHT
else:
raise Exception("Dataset " + name + " not found.")


LayerDict["train_resize"]["layer"] = ResizeIfMoreThan(frames=input_height)
LayerDict["test_resize"]["layer"] = ResizeIfMoreThan(frames=input_height)
LayerDict["pad"]["layer"] = PadIfLessThan(frames=input_height)

self.ds = ds
self.name = name
self.num_train_examples = num_train_examples
self.num_val_examples = num_val_examples
self.num_test_examples = num_test_examples
self.num_total_examples = num_total_examples
self.input_height = input_height
self.input_width = info.features['pose'].shape[1]
self.num_classes = info.features['label'].num_classes

Expand All @@ -239,7 +255,7 @@ def train_map_fn(x, y):
batch = RemoveZ()(batch)
batch = preprocessing_pipeline(batch, training=True)
x = tf.ensure_shape(
batch[0], [MIN_INPUT_HEIGHT, self.input_width, 2])
batch[0], [self.input_height, self.input_width, 3])
return x, y

train_ds = self.ds["train"]
Expand Down
14 changes: 7 additions & 7 deletions datasets/download_datasets.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
wget -O autsl_tssi.zip https://storage.googleapis.com/slr_tfds_datasets/autsl_tssi.zip
wget -O autsl_tssi.zip https://storage.googleapis.com/slr_tfds_datasets/wlasl100_tssi.zip
wget -O autsl_tssi.zip https://storage.googleapis.com/slr_tfds_datasets/mejiaperez_tssi.zip
unzip autsl_tssi.zip
# wget -O autsl_tssi.zip https://storage.googleapis.com/slr_tfds_datasets/autsl_tssi.zip
wget -O wlasl100_tssi.zip https://storage.googleapis.com/slr_tfds_datasets/wlasl100_tssi.zip
# wget -O mejiaperez_tssi.zip https://storage.googleapis.com/slr_tfds_datasets/mejiaperez_tssi.zip
# unzip autsl_tssi.zip
unzip wlasl100_tssi.zip
unzip mejiaperez_tssi.zip
rm autsl_tssi.zip
# unzip mejiaperez_tssi.zip
# rm autsl_tssi.zip
rm wlasl100_tssi.zip
rm mejiaperez_tssi.zip
# rm mejiaperez_tssi.zip
38 changes: 1 addition & 37 deletions model.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import tensorflow as tf
from efficient_net_b0 import EfficientNetB0
from loss import select_loss
from tensorflow.keras.metrics import TopKCategoricalAccuracy
from tensorflow.keras.layers import Dropout, Dense
from tensorflow.keras import Input
from tensorflow.keras.models import Model
from tensorflow.keras.applications.densenet import DenseNet121
# from tensorflow.keras.applications.efficientnet import EfficientNetB0


def build_densenet121_model(input_shape=[None, 135, 2],
dropout=0,
optimizer=None,
pretraining=False,
use_loss="crossentroypy",
use_loss="crossentropy",
num_classes=None):
# setup backbone
weights = 'imagenet' if pretraining else None
Expand Down Expand Up @@ -41,37 +39,3 @@ def build_densenet121_model(input_shape=[None, 135, 2],
model.compile(optimizer=optimizer, loss=loss, metrics=metrics)

return model


def build_efficientnet_model(input_shape=[None, 128, 3],
dropout=0,
optimizer=None,
pretraining=True,
use_loss="crossentropy",
num_classes=100):
# setup backbone
weights = "imagenet" if pretraining else None
backbone = EfficientNetB0(input_shape=input_shape,
weights=weights,
include_top=False,
pooling="avg")

# setup model
inputs = Input(shape=input_shape)
x = backbone(inputs)
x = Dropout(dropout)(x)
predictions = Dense(num_classes, activation='softmax')(x)
model = Model(inputs=inputs, outputs=predictions)

# setup the metrics
metrics = [
TopKCategoricalAccuracy(k=1, name='top_1', dtype=tf.float32)
]

# setup the model
loss = select_loss(use_loss)

# compile the model
model.compile(optimizer=optimizer, loss=loss, metrics=metrics)

return model
Loading

0 comments on commit c73db99

Please sign in to comment.