machine-learning - 如何将深度学习模型的类别和类别作为标签传递?
问题描述
我正在尝试制作一个 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
解决方案
推荐阅读
- mysql - 如何在codeigniter中使用多个where条件?
- python - 尝试编辑 configuration.yaml 但出错
- r - Merging two list columns based on a condition
- flutter - 如何在flutter中生成有效期为15秒的ID?
- elasticsearch - 如何在不同的集群上恢复 elasticsearch s3 快照
- java - 记录 Spring Boot 应用程序的控制台(WAR 文件)
- asp.net - 从 ASP.NET 中的 Web 配置转换默认文档属性
- python - 将复杂的 XML 转换为 CSV
- node.js - Sequelize: throw new Error(`${this.name}.belongsToMany 调用的东西不是 Sequelize.Model 的子类
- android - 无法使用 URI 序列化对象