Home > database >  When recognizing hand gesture classes, I always get the same class in Keras
When recognizing hand gesture classes, I always get the same class in Keras

Time:02-18

When recognizing hand gesture classes, I always get the same class, although I tried changing the parameters and even passed the data without normalization:

df_train = pd.read_csv('train_dataset.csv')
df_train = df_train.drop(columns=['Unnamed: 0'], axis=1)
df_train = df_train.fillna(0)

x_train = df_train.drop(['y'], axis=1)
y_train = df_train['y']

x_train = x_train / 310

model = keras.models.Sequential([Dense(32, input_shape=(42,), activation='relu'),
                                Dense(64, activation='relu'),
                                Dense(6, activation='softmax')])

model.compile(optimizer='adam',
             loss='categorical_crossentropy',
             metrics=['accuracy'])

model.fit(x_train, y_train_cat, batch_size=16, epochs=9, validation_split=0.2)

model.save("gestures_model.h5")

Here is a main code:

REV_CLASS_MAP = {
    0: "up",
    1: "down",
    2: "right",
    3: "left",
    4: "forward",
    5: "back"
}

def mapper(val):
    return REV_CLASS_MAP[val]

if len(data[data.index(new_row)]) > 0:
    df = pd.DataFrame(data, columns=columns)
    df = df.fillna(0)
    df = df / 310
    pred = model.predict(df)
    move_code = np.argmax(pred[0])
    user_move_name = mapper(move_code)
    print(user_move_name)

Here is an example of input data:

56,172,72,169,88,155,100,144,111,139,78,120,81,94,82,77,82,62,66,120,62,104,62,124,64,136,54,122,50,110,52,130,55,139,43,126,40,114,42,129,45,137,0

What am I doing wrong and how to fix it? I noticed that in my data there are rows in which there is only one number. Could this be the cause of my problem? ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ P.S I am new to neural networks and keras.

CodePudding user response:

All rows need the same data size, of course some values can be empty in csv.

feature1, feature2, feature3,y
aaa,bbb,3.0,2.0
bbb, ,4.1, 3.1

You need to impute empty values by using for example most frequent value for categorical values or median for numerical values. Predicted value cant be empty

  • Related