问题描述
我是这个平台的新手,没有编码背景。但是对于我的论文,我坚持使用评估代码。 我正在使用 DeeplabV3+ 的 Keras 实现,对于评估代码,我得到了标签,但我无法计算结果的评估指标和混淆矩阵。我的基本事实是 png 图像格式,我使用的是自定义数据集。下面是标签预测的代码,我指的是github repo: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)),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)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)