3个课程预测CNN深度学习
我在三个类中训练了模型,现在我想一次输入一个图像,看看它属于1,2类还是3类。
data = []
img_size = 224
for i in categories:
path = os.path.join(TRAIN_DIR1, i)
class_num = categories.index(i)
for file in os.listdir(path):
filepath = os.path.join(path, file)
img = cv2.imread(filepath, 0)
img = cv2.resize(img, (img_size, img_size))
data.append([img, class_num])
random.shuffle(data)
X, y = [], []
for feature, label in data:
X.append(feature)
y.append(label)
X = np.array(X).reshape(-1, img_size, img_size, 1)
X = X / 255.0
y = np.array(y)
X_train, X_valid, y_train, y_valid = train_test_split(X, y, random_state=20, stratify=y)
X_train = X_train.reshape(X_train.shape[0], img_size*img_size*1)
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
我需要帮助编写我的预测代码以一次输入一个测试图像。
I trained my model in three classes and now I want to input one image at a time to see whether it belongs to classes 1,2, or 3.
data = []
img_size = 224
for i in categories:
path = os.path.join(TRAIN_DIR1, i)
class_num = categories.index(i)
for file in os.listdir(path):
filepath = os.path.join(path, file)
img = cv2.imread(filepath, 0)
img = cv2.resize(img, (img_size, img_size))
data.append([img, class_num])
random.shuffle(data)
X, y = [], []
for feature, label in data:
X.append(feature)
y.append(label)
X = np.array(X).reshape(-1, img_size, img_size, 1)
X = X / 255.0
y = np.array(y)
X_train, X_valid, y_train, y_valid = train_test_split(X, y, random_state=20, stratify=y)
X_train = X_train.reshape(X_train.shape[0], img_size*img_size*1)
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
I need help writing my prediction code to input one testing image at a time, please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您输入
退出
时,您可以使用way循环连续输入IMG目录。You can use a while loop to continuously enter the img directory with
break
when you inputquit
.