+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

如何在评估代码中生成混淆矩阵,以实现DeeplabV3 +的Keras实现

发布于2021-03-05 09:38     阅读(371)     评论(0)     点赞(25)     收藏(4)


0

1

2

3

4

5

6

我是这个平台的新手,没有任何编码背景。但是对于我的论文,我坚持使用评估代码。我正在使用DeeplabV3 +的Keras实现,对于评估代码,我正在获取标签,但无法计算结果的评估指标和混淆矩阵。我的基本事实是png图像格式,我正在使用自定义数据集。以下是标签预测的代码,我指的是github回购:https : //github.com/bonlime/keras-deeplab-v3-plus

import numpy as np
from PIL import Image
from sklearn import metrics
from sklearn.metrics import confusion_matrix 
from matplotlib import pyplot as plt
import tensorflow as tf
import keras
import cv2
import pandas as pd

from keras.models import load_model

from model import Deeplabv3

# Generates labels using most basic setup.  Supports various image sizes.  Returns image labels in same format
# as original image.  Normalization matches MobileNetV2
#tunnel_weigths_path = 'C:/Users/t-92swsw1mpg.C-VG-202092002/.spyder-py3/temp_path/4/weights-improvement-148-0.02.hdf5'
trained_image_width=256
trained_image_height=256
mean_subtraction_value=63.75
#data_path = "C:/Users/t-92swsw1mpg.C-VG-202092002/.spyder-py3/benchmark_dataset/VOC2012/JPEGImages/"
#main_path = "C:/Users/t-92swsw1mpg.C-VG-202092002/.spyder-py3/"

image = np.array(Image.open('data_augmentation/dataset/augmented/data/augmented_image_25.jpg'))
# resize to max dimension of images from training dataset
w, h, _ = image.shape
# ratio = float(trained_image_width) / np.max([w, h])
resized_image = np.array(Image.fromarray(image.astype('uint8')).resize((int(trained_image_height), int(trained_image_width))))

# apply normalization for trained dataset images
resized_image = (resized_image / mean_subtraction_value) - 1.

# pad array to square image to match training images
pad_x = int(trained_image_width - resized_image.shape[0])
pad_y = int(trained_image_width - resized_image.shape[1])
resized_image = np.pad(resized_image, ((0, pad_x), (0, pad_y), (0, 0)), mode='constant')

# make prediction

deeplab_model = Deeplabv3(weights= None , input_tensor= None, input_shape=(256, 256, 3), classes=21, backbone='xception',
              OS=8, alpha=1., activation= None)

res = deeplab_model.predict(np.expand_dims(resized_image, 0))
labels = np.argmax(res.squeeze(), -1)
# remove padding and resize back to original image
if pad_x > 0:
    labels_x = labels[:-pad_x]
if pad_y > 0:
    labels_y = labels[:, :-pad_y]
labels = np.array(Image.fromarray(labels.astype('uint8')).resize((h, w)))

print("This is the Model", deeplab_model)

print("We are in the end!")
deeplab_model.summary()
plt.imshow(labels)

可以帮助我,告诉我在生成标签(预测)后如何生成混淆矩阵。


解决方案


暂无回答

0

1

2

3

4

5

6

7



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接: https://www.pythonheidong.com/blog/article/879503/c28e9d0f905a54fac43d/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

25 0
收藏该文
已收藏

评论内容:(最多支持255个字符)