首页 > 解决方案 > 如何将深度学习模型的类别和类别作为标签传递?

问题描述

我正在尝试制作一个 CNN 模型,在该模型中将训练不同品牌的徽标,我想知道类别和类是如何传递给模型的。我最近训练了只预测类别的分类器,现在想知道它是如何预测类别的。示例: 类别:医疗类 [Panadol, Paracetamol, Albertsons] 如何编写类别代码,因为我有不同数量的类别。我正在尝试以下代码,该代码不适 用于类别和类的代码

    DATADIR = "/content/drive/MyDrive/DataSet/"
    CATEGORIES=['Food','Medical']
    CLASSES = ["Burger King","Cadbury","coca cola","Friskies","KFC","Kitkat","Knorr","Lipton","Maltesers","McDonald's","Oral-B","pepsi",
    "Pizza Hut","Tic Tac","Wall's"]
     for category in CATEGORIES: 
        path = os.path.join(DATADIR,category)  
        for classes in CLASSES:
          complete_path = os.path.join(path,classes) 
          class_num = CLASSES.index(classes) 
          for img in tqdm(os.listdir(complete_path)):  
            try:
                img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE)  
                new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))  
                training_data.append([new_array, class_num]) 
            except Exception as e:  
                pass
          

如果我在CLASSES中也写了医学类的数量,它会从食物目录中找到医学类,如何修改代码,因为我的目标是首先移动到食物类,追踪所有食物类的类,只要食物类别结束,它会回溯到下一个类别等等,它将如何通过?

仅有效的类代码

DATADIR = "/content/drive/MyDrive/DataSet/Food"


# Defining the number of classes 
CATEGORIES = ["Burger King","Cadbury","coca cola","Friskies","KFC","Kitkat","Knorr","Lipton","Maltesers","McDonald's","Oral-B",
"pepsi","Pizza Hut","Tic Tac","Wall's"]

for category in CATEGORIES: 
    path = os.path.join(DATADIR,category)  
    for img in os.listdir(path):  
        img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE) 
        plt.imshow(img_array, cmap='gray')  
        plt.show()  
        break 
    break  

标签: machine-learningdeep-learningneural-networkmodelconv-neural-network

解决方案


推荐阅读