【问题标题】:Load_model and calculate accuracy for predicts加载模型并计算预测的准确性
【发布时间】:2020-08-17 13:21:59
【问题描述】:
i = Input(shape=(100,100,1,))

x = Conv2D(32,(3,3),strides=1,activation='relu')(i)
x = BatchNormalization()(x)
x = MaxPooling2D((2, 2))(x)

x = Conv2D(64,(3,3),strides=1,activation='relu')(x)
x = BatchNormalization()(x)
x = MaxPooling2D((2, 2))(x)

x = Conv2D(128,(3,3),strides=1,activation='relu')(x)
x = BatchNormalization()(x)
x = MaxPooling2D((2, 2))(x)

x = Flatten()(x)
x = Dropout(0.2)(x)
x = Dense(50, activation='relu')(x)
x = Dense(2, activation='softmax')(x)

model = Model(i,x)
model.compile(optimizer='adam',loss='sparse_categorical_crossentropy', 
metrics= ['accuracy'])

train_data, test_data, train_target, test_target = 
train_test_split(data,target,test_size=0.1)

checkpoint = ModelCheckpoint('model_mask.h5',monitor='val_loss',verbose=0,
save_best_only=True,mode='auto')


history = model.fit(train_data,train_target,epochs=20,callbacks= 
[checkpoint],validation_data=(test_data,test_target))

那是我的模型,模型工作得很好。

model = load_model("model_mask.h5")  

img_resp = requests.get(url=url)
img_arr = np.array(bytearray(img_resp.content),dtype=np.uint8)
img = cv2.imdecode(img_arr, cv2.IMREAD_COLOR)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces = face_clsfr.detectMultiScale(gray,1.3,5)

face_img = gray[y:y+w,x:x+w]
resized = cv2.resize(face_img,(100,100))
normalized = resized/255.0
reshaped = np.reshape(normalized,(1,100,100,1))
result = model.predict(reshaped)

我上传了经过训练的模型。它还可以打开或关闭其预测掩码。但我想找到准确性。 我正在使用 openCv 和 python。我训练了我的模型并上传了它。但是现在我想计算相机快照的准确性?我该如何编码?

【问题讨论】:

  • 如果你不提供足够的信息,你永远不会得到答案,你的模型是什么,你的图像是什么,你的任务是什么......
  • 好的,我要去编辑了

标签: python keras file-upload


【解决方案1】:

如果您想获得分类指标,您需要一组测试图像。然后,您需要记录测试集中所有图像的预测标签和真实标签。完成所有这些后,您就可以计算出您想要的任何指标。

【讨论】:

  • 所以你在说,我必须在保存模型之前进行评估?但我无法解决代码?
  • 不,你可以离线评估你只需要在测试集上运行预测......
  • 如何离线评估。我正在考虑我的代码正在运行,但我想当相机找到一张脸时,找出你戴口罩的准确度
  • 您必须提前测量,向其展示一堆静止图像并计算真阳性、真阴性等。
  • 对不起我的英语。我无法理解你。我用大约 4000 张图像训练了模型。然后我保存它这个模型。现在我打开新项目并加载模型。没关系。然后我用相机拍了照片。模型预测得很好。现在我只想看看这些快照的准确性
猜你喜欢
  • 2012-07-10
  • 1970-01-01
  • 2020-12-31
  • 2016-08-08
  • 1970-01-01
  • 1970-01-01
  • 2023-03-05
  • 2020-02-12
  • 2020-11-18
相关资源
最近更新 更多