[英]Deep Learning model not accurately predicting , Keras?
I am new to Deep Learning and Keras.我是深度学习和 Keras 的新手。 I have created a model that trains on the ASL(American Sign Language) dataset with nearly 80,000 training images and 1500 testing images.
我创建了一个在 ASL(美国手语)数据集上训练的模型,其中包含近 80,000 个训练图像和 1500 个测试图像。 I have also appended some more classes ie.
我还附加了一些更多的类,即。 Hand sign numbers from 0-9.
手签数字从 0 到 9。 So, in total, I have 39 classes (0-9 and AZ).
所以,我总共有 39 个班级(0-9 和 AZ)。 My task is to training this dataset and use it for prediction.
我的任务是训练这个数据集并将其用于预测。 My input for prediction would be a frame from a webcam where I'll be displaying the hand sign.
我的预测输入是来自网络摄像头的帧,我将在其中显示手势。
classifier = Sequential()
classifier.add(Conv2D(32, (3, 3), input_shape = (100, 100, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Conv2D(32, (3, 3), activation = 'relu'))
classifier.add(MaxPooling2D(pool_size = (2, 2)))
classifier.add(Flatten())
classifier.add(Dense(units = 128, activation = 'relu'))
classifier.add(Dense(units = 39, activation = 'softmax'))
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(rescale = 1./255,
shear_range = 0.2,
zoom_range = 0.2,
horizontal_flip = True)
test_datagen = ImageDataGenerator(rescale = 1./255)
training_set = train_datagen.flow_from_directory('train',
target_size = (100,100),
batch_size = 128,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory('test',
target_size = (100, 100),
batch_size = 128,
class_mode = 'categorical')
classifier.fit_generator(training_set,
steps_per_epoch = 88534,
epochs = 10,
validation_data = test_set,
validation_steps = 1418)
The ASL dataset images are of size 200x200 and the number sign datasets are of size 64x64. ASL 数据集图像大小为 200x200,数字符号数据集大小为 64x64。 After running for 5 epocs with validation accuracy 96% I am still not able to get good predictions when I run it on a video.
在以 96% 的验证准确率运行 5 个 epoc 之后,当我在视频上运行它时,我仍然无法获得良好的预测。
classifier = load_model('asl_original.h5')
classifier.compile(loss='binary_crossentropy',optimizer='rmsprop',metrics=['accuracy'])
cam = cv2.VideoCapture(0)
while(1):
try:
ret, frame = cam.read()
frame = cv2.flip(frame,1)
roi = frame[100:400,200:500]
cv2.rectangle(frame,(200,100),(500,400),(0,255,0),2)
cv2.imshow('frame',frame)
cv2.imshow('roi',roi)
img = cv2.resize(roi,(100,100))
img = np.reshape(img,[1,100,100,3])
classes = classifier.predict_classes(img)
print(classes)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
except Exception:
traceback.print_exc()
pass
I Don't understand why am I not able to get accurate predictions even after training on such a large dataset.我不明白为什么即使在如此大的数据集上训练后我也无法获得准确的预测。 What changes do I need to make so that I get accurate predictions for all my 39 classes.
我需要进行哪些更改才能对所有 39 个课程进行准确预测。
Link for the datasets.数据集的链接。 ASL DATASET and Hand sign for numbers
ASL 数据集和数字的手势
In the classifier.compile you use the loss='binary_crossentropy' that is used only where the labels are binary (only two classes).在classifier.compile 中,您使用loss='binary_crossentropy',它仅在标签是二进制的(只有两个类)时使用。 When you have multiclass classification you must use the appropriate loss function based on the numbers and types of your labels (ie 'sparse_categorical_crossentropy').
当您进行多类分类时,您必须根据标签的数量和类型(即“sparse_categorical_crossentropy”)使用适当的损失函数。
Try to read this useful blog post that explains every loss function in details.尝试阅读这篇有用的博客文章,其中详细解释了每个损失函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.