【王者荣耀】皮肤-英雄 预测(tensorflow)

【王者荣耀】皮肤-英雄 预测(tensorflow),第1张

本项目的思路是通过英雄的多个皮肤进行模型的训练,进而对给定的原皮实施对应英雄的预测。包括的模块有dataset的建立,卷积神经网络模型等。

码云开源地址:aov_ornament-hero: 皮肤进行模型训练原皮进行英雄预测

网盘下载地址:http://www.kaotop.com/file/tupian/20220423/") # # probability_model = tf.keras.Sequential([model, tf.keras.layers.Softmax()]) # predictions = probability_model.predict(guess_images) "结果输出" print(class_names[np.argmax(predictions[2])]) # "训练模型" # history = model.fit(train_images, train_labels, epochs=10, # validation_data=(test_images, test_labels)) # # "评估准确度" # plt.plot(history.history['accuracy'], label='accuracy') # plt.plot(history.history['val_accuracy'], label = 'val_accuracy') # plt.xlabel('Epoch') # plt.ylabel('Accuracy') # plt.ylim([0.5, 1]) # plt.legend(loc='lower right') # plt.show() 2、dataset.py

import functions2


"设置datasetss类"
class datasetss():
    def __init__(self):
        self.train_images = functions2.get_train_images()
        self.train_labels = functions2.get_train_labels()
        self.test_images = functions2.get_test_images()
        self.test_labels = functions2.get_test_labels()
3、function2.py
import cv2 as cv
import numpy as np


"设置train与test标签"
trainfile_labels = ["00", "01", "02", "03", "04", "05",
                    "10", "11", "12", "13", "14", "15", "16", "17",
                    "20", "21", "22", "23", "24", "25", "26",
                    "30", "31", "32", "33", "34", "35",
                    "40", "41", "42", "43", "44"]
testfile_labels = ["0", "1", "2", "3", "4"]


"train_images"
def get_train_images():
    # 构建全零ndarray
    train_images = np.zeros((32, 50, 50, 3))
    i = 0
    for label in trainfile_labels:
        # 选择路径名
        image_path = "D:/WZRY_Project/aov_ornament-hero/images/train_images/" + label + ".jpg"
        # 以RGB模式读取image
        img_ini = cv.imread(image_path, 1)
        # 缩小image到50x50像素
        img_fin = cv.resize(img_ini, (50, 50), interpolation=cv.INTER_CUBIC)
        # 将三维数组赋值给四维数组的后三维
        train_images[i, :, :, :] = img_fin
        i = i + 1
    return train_images


"train_labels"
def get_train_labels():
    # 构建全零ndarray
    train_labels = np.zeros((32, 1))
    i = 0
    for label in trainfile_labels:
        # 将一维数组赋值给二维数组的第二维
        train_labels[i][0] = label[0]
        i = i + 1
    return train_labels


"test_images"
def get_test_images():
    test_images = np.zeros((5, 50, 50, 3))
    i = 0
    for label in testfile_labels:
        image_path = "D:/WZRY_Project/aov_ornament-hero/images/test_images/" + label + ".jpg"
        img_ini = cv.imread(image_path, 1)
        img_fin = cv.resize(img_ini, (50, 50), interpolation=cv.INTER_CUBIC)
        test_images[i, :, :, :] = img_fin
        i = i + 1
    return test_images


"test_labels"
def get_test_labels():
    test_labels = np.zeros((5, 1))
    i = 0
    for label in testfile_labels:
        test_labels[i][0] = label[0]
        i = i + 1
    return test_labels

4.create_test_images.py
import cv2 as cv
import numpy as np


def create_test_images(name):
    test_images = np.zeros((1, 50, 50, 3))
    image_path = "D:/WZRY_Project/aov_ornament-hero/images/guess_images/" + name
    img_ini = cv.imread(image_path, 1)
    img_fin = cv.resize(img_ini, (50, 50), interpolation=cv.INTER_CUBIC)
    test_images[0, :, :, :] = img_fin
    return test_images
三、结语

很遗憾,这个项目的预测并不准确,究其原因便是训练集太小了。然而,其中的各种方法依旧对于新手有借鉴意义。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/719052.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存