Python 负荷_模型及预测的计算精度
这是我的模型,模型运行得很好Python 负荷_模型及预测的计算精度,python,keras,file-upload,Python,Keras,File Upload,这是我的模型,模型运行得很好 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 = MaxPooling2
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))
我上传了我训练过的模型。此外,它还可以打开或关闭预测遮罩。但我想找到准确度。
我正在使用openCv和python。我训练了我的模型并上传了它。但现在我想计算相机快照的准确度?如何编写代码?如果要获得分类指标,需要一组图像测试。然后,您需要记录测试集中所有图像的预测标签和真实标签。在您完成所有这些之后,您将能够计算您想要的任何指标。如果您没有提供足够的信息,您的模型是什么,您的图像是什么,您的任务是什么……好的,我将编辑。那么您说的是,我必须在保存模型之前进行评估吗?但我不能解决代码?不,你可以离线评估你只需要在测试集上运行预测…我如何离线评估。我正在进行精确测量,我的代码正在运行,但我想当相机找到一张脸时,找出你戴着面具的准确度,提前测量,给它看一堆静止的图像,并计算真正片,真负片,等等。我为我的英语感到抱歉。我不能理解你。我用大约4000张图片训练了这个模型。然后我把它保存在这个模型中。现在我打开新的项目和加载模型。没关系。然后我用相机拍下了这些快照。模型预测效果很好。现在我只想看看这些快照的准确性
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)