I'm trying to do real time gesture recognition but I'm new to tensorflow and keras so I took this code as a base https://github.com/CircuitDigest/Rock-Paper-Scissors-with-Pi/blob/main/training .py I installed keras and tensorflow but when I run the script I get this error:
Traceback (most recent call last):
File "C:/Users/belog/drone_sees/train_model.py", line 61, in <module>
model = get_model()
File "C:/Users/belog/drone_sees/train_model.py", line 30, in get_model
SqueezeNet(input_shape=(227, 227, 3), include_top=False),
File "C:\Users\belog\drone_sees\venv\lib\site-packages\keras_squeezenet\squeezenet.py", line 133, in SqueezeNet
model.load_weights(weights_path)
File "C:\Users\belog\drone_sees\venv\lib\site-packages\keras\engine\topology.py", line 2622, in load_weights
load_weights_from_hdf5_group(f, self.layers)
File "C:\Users\belog\drone_sees\venv\lib\site-packages\keras\engine\topology.py", line 3089, in load_weights_from_hdf5_group
original_keras_version = f.attrs['keras_version'].decode('utf8')
AttributeError: 'str' object has no attribute 'decode'
Process finished with exit code 1
Here is my script:
import cv2
import numpy as np
from keras_squeezenet import SqueezeNet
from keras.optimizers import Adam
from keras.utils import np_utils
from keras.layers import Activation, Dropout, Convolution2D, GlobalAveragePooling2D
from keras.models import Sequential
import tensorflow as tf
import os
IMG_SAVE_PATH = 'images'
CLASS_MAP = {
"forward": 0,
"back": 1,
"up": 2,
"down": 3,
"stop": 4
}
NUM_CLASSES = len(CLASS_MAP)
def mapper(val):
return CLASS_MAP[val]
def get_model():
model = Sequential([
SqueezeNet(input_shape=(227, 227, 3), include_top=False),
Dropout(0.5),
Convolution2D(NUM_CLASSES, (1, 1), padding='valid'),
Activation('relu'),
GlobalAveragePooling2D(),
Activation('softmax')
])
return model
dataset = []
for directory in os.listdir(IMG_SAVE_PATH):
path = os.path.join(IMG_SAVE_PATH, directory)
if not os.path.isdir(path):
continue
for item in os.listdir(path):
if item.startswith("."):
continue
img = cv2.imread(os.path.join(path, item))
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.resize(img, (227, 227))
dataset.append([img, directory])
data, labels = zip(*dataset)
labels = list(map(mapper, labels))
# one hot encode the labels
labels = np_utils.to_categorical(labels)
# define the model
model = get_model()
model.compile(
optimizer=Adam(lr=0.0001),
loss='categorical_crossentropy',
metrics=['accuracy']
)
model.fit(np.array(data), np.array(labels), epochs=15)
model.save("gestures_model.h5")
What am I doing wrong and how to fix this error? (I use tensorflow==1.14.0 and keras==2.1.1)