我是机器学习新手,在图像分类方面遇到一些问题。使用简单的分类器技术 K 最近邻居,我试图区分猫和狗。
到目前为止我的代码:
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline
DATADIR = "/Users/me/Desktop/ds2/ML_image_classification/kagglecatsanddogs_3367a/PetImages"
CATEGORIES = ['Dog', 'Cat']
IMG_SIZE = 30
data = []
categories = []
for category in CATEGORIES:
path = os.path.join(DATADIR, category)
categ_id = CATEGORIES.index(category)
for img in os.listdir(path):
try:
img_array = cv2.imread(os.path.join(path,img), 0)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
data.append(new_array)
categories.append(categ_id)
except Exception as e:
# print(e)
pass
print(data[0])
s1 = pd.Series(data)
s2 = pd.Series(categories)
frame …Run Code Online (Sandbox Code Playgroud)