Wednesday, 23 February 2022

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

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.

New

Here is df_train before processing:

,x11,x21,x12,x22,x13,x23,x14,x24,x15,x25,x16,x26,x17,x27,x18,x28,x19,x29,x110,x210,x111,x211,x112,x212,x113,x213,114,214,115,x215,x116,x216,x117,x217,x118,x218,x119,x219,x120,x220,x121,x221,y
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
...
84,166,96,158,108,143,108,131,101,127,87,145,87,128,90,118,94,111,74,147,76,119,81,114,84,115,64,148,66,120,72,119,74,124,56,148,57,124,61,124,63,129,5

Here is df_train after processing:

     x11  x21  x12  x22  x13  x23  x14  ...  x119  x219  x120  x220  x121  x221    y
0     56  175   73  168   88  155  101  ...    42   113    44   130    47   138  0.0
1    172   72  169   88  155  100  144  ...   114    42   129    45   137     0  0.0
2    172   72  169   88  155  100  144  ...   114    42   129    45   137     0  0.0
3    174   74  167   89  155  101  144  ...   115    44   130    46   137     0  0.0
4    174   74  169   90  155  101  144  ...   114    44   128    46   136     0  0.0
..   ...  ...  ...  ...  ...  ...  ...  ...   ...   ...   ...   ...   ...   ...  ...
843  166   96  158  108  143  108  131  ...   124    61   124    63   129     5  0.0
844  166   94  158  105  145  104  132  ...   128    58   130    59   134     5  0.0
845  164   90  155  101  141  100  129  ...   126    55   129    57   134     5  0.0
846  158   88  152   99  140   96  128  ...   142    54   150    58   146     5  0.0
847  158   88  152   99  140   96  128  ...   142    54   150    58   146     5  0.0

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀



from When recognizing hand gesture classes, I always get the same class in Keras

No comments:

Post a Comment