JudyJ
51
2020-12-19 03:23:01
0
127

python Precision and F-score are ill-defined


원래 소스코드는 label이 mask, withoutmask 두개였는데 저는 mask, withoutmask, wrongmask 해서 마스크 감지할려고 소스를 수정중입니다. 근데 wrongmask파일을 만들고 실행을 했는데 wrong_mask에서는 precision, recall f1-score가 다 0이뜹니다. 

UndefinedMetricWarning: Precision and F-score are ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.

  _warn_prf(average, modifier, msg_start, len(result))

              precision    recall  f1-score   support


   with_mask       0.95      0.99      0.97       373

without_mask       0.99      0.99      0.99       386

  wrong_mask       0.00      0.00      0.00        16


    accuracy                           0.97       775

   macro avg       0.65      0.66      0.65       775

weighted avg       0.95      0.97      0.96       775

# train the head of the network
print("[INFO] training head...")
H = model.fit(
	aug.flow(trainX, trainY, batch_size=BS),
	steps_per_epoch=len(trainX) // BS,
	validation_data=(testX, testY),
	validation_steps=len(testX) // BS,
	epochs=EPOCHS)

# make predictions on the testing set
print("[INFO] evaluating network...")
predIdxs = model.predict(testX, batch_size=BS)

# for each image in the testing set we need to find the index of the
# label with corresponding largest predicted probability
predIdxs = np.argmax(predIdxs, axis=1)

# show a nicely formatted classification report
print(classification_report(testY.argmax(axis=1), predIdxs,
	target_names=labelNames))

# serialize the model to disk
print("[INFO] saving mask detector model...")
model.save(args["model"], save_format="h5")

# plot the training loss and accuracy
N = EPOCHS
plt.style.use("ggplot")
plt.figure()
plt.plot(np.arange(0, N), H.history["loss"], label="train_loss")
plt.plot(np.arange(0, N), H.history["val_loss"], label="val_loss")
plt.plot(np.arange(0, N), H.history["accuracy"], label="train_acc")
plt.plot(np.arange(0, N), H.history["val_accuracy"], label="val_acc")
plt.title("Training Loss and Accuracy")
plt.xlabel("Epoch #")
plt.ylabel("Loss/Accuracy")
plt.legend(loc="lower left")
plt.savefig(args["plot"])

제 생각에는

print(classification_report(testY.argmax(axis=1), predIdxs, target_names=labelNames))

이 행에서 제대로 안되는 것 같은데,어떻게 해결할 수 있을까요.

0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.