(二)人工智能,深度学习,卷积神经网络,keras 自己制作数据集 ,自己搭建模型, 对多种类图片进行分类 ,史上最详细。 tensorflow,小白必备,代码讲解,多图预警,

前期的环境准备,数据集制备,和模型搭建,及训练参数的调整,见我上篇博客:

https://blog.csdn.net/a721867783/article/details/92645557

本篇博客呢主要简单写下,模型预测的代码:包括数据集制备及送入模型,和预测结果展示。预测结果由于时间问题没有进行后期可视化处理,但是数据结果是有的。废话少说,开始正题。

一,数据预处理

本次数据预处理比较简单,可以直接用模型数据预处理的代码

def load_data(path):
    print("[INFO] 数据载入")
    data = []
    labels = []
    # grab the image paths and randomly shuffle them
    imagePaths = sorted(list(paths.list_images(path)))
    # loop over the input images
    for imagePath in imagePaths:
        # load the image, pre-process it, and store it in the data list
        image = cv2.imread(imagePath)
        print('显示图片列表')
        print(imagePath)
        image = cv2.resize(image, (240, 240))
        image = img_to_array(image)
        data.append(image)

        # extract the class label from the image path and update the
        # labels list
        label = int(imagePath.split(os.path.sep)[-2])       
        labels.append(label)
    
    # scale the raw pixel intensities to the range [0, 1]
    data = np.array(data, dtype="float") / 255.0
    labels = np.array(labels)
    print(labels)

    # convert the labels from integers to vectors
    labels = to_categorical(labels)  
    print(labels)                       
    return data,labels


if __name__=='__main__':
   # args = args_parse()
 #   file_path = args["dataset"]
    trainX,trainY = load_data('D:\\sort1\\sort_test\\')

== 提示:注意修改数据路径文件 trainX,trainY = load_data(‘D:\sort1\sort_test\’)==

二, 模型载入与预测结果

好吧,偷个懒,后期简单处理,y中包含所有结果准确率最高的,就是我们预测结果,同时呢我输出了标签,可以将标签和预测结果进行对比就可以。

print("[INFO] loading network...")
model = load_model('model_sort.h5')
y = model.predict(trainX,batch_size=2)
print(y)



偷个懒,嘿嘿
主要参考:原创
https://www.cnblogs.com/skyfsm/p/8051705.html
有需要深入交流的或者代做的qq:721867783 ,或者给我私信, 目标检测, 图像处理,分类识别,我都熟悉。
在这里插入图片描述


版权声明:本文为a721867783原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。