ive been working on a sign language recognition. i extracted landmarks with mediapipe, saved it as .parquets then padded the data to create uniform length. each row of landmark has 21 node with x,y,z coordinate as shown. the padding done according to max_frame_size i found among all videos (311).
Padded .parquets structure:
filename class_id frame landmarks
signer1_sample1 1 1 [[0.1, 0.2, 0.3], [0.4, 0.5, 0.6], ..., [0.1, 0.2, 0.8]]
signer1_sample1 1 2 [[0.2, 0.3, 0.4], [0.5, 0.6, 0.7], ..., [0.3, 0.7, 0.4]]
... ... ... ...
signer1_sample1 1 311 [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], ..., [0.0, 0.0, 0.0]]
... ... ... ...
... ... ... ...
signerX_sampleY Z 311 [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0], ..., [0.0, 0.0, 0.0]]
i was expecting to get 311*21 length np.array for each class_id with this code block, so that i could build & train my model.
def prepare_data(df, max_frame_size=311):
X = []
y = []
for filename, group in df.groupby('filename'):
frames = group['landmarks'].tolist()
if len(frames) < max_frame_size:
frames += [[(0.0, 0.0, 0.0)] * 21] * (max_frame_size - len(frames))
else:
frames = frames[:max_frame_size]
frames = [np.array(frame).flatten() for frame in frames]
X.append(frames)
y.append(group['class_id'].iloc[0])
X = np.array(X)
y = np.array(y)
return X, y
the model i used results in
model = Sequential([
Masking(mask_value=0.0, input_shape=(max_frame_size,63)),
LSTM(64, return_sequences=True, activation='relu'),
BatchNormalization(),
Dropout(0.5),
LSTM(128, return_sequences=True, activation='relu'),
BatchNormalization(),
Dropout(0.5),
LSTM(64, return_sequences=False, activation='relu'),
BatchNormalization(),
Dense(64, activation='relu'),
Dense(32, activation='relu'),
Dense(len(label_encoder.classes_), activation='softmax')
early_stopping = EarlyStopping(monitor='val_loss', patience=5, restore_best_weights=True)
history = model.fit(
X_train, y_train,
validation_data=(X_validation, y_validation),
epochs=50,
batch_size=32,
callbacks=[early_stopping]
])
`ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray).
How can i correctly process the padded parquets and setup model?
karesosis is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.