猫狗数据遮挡部分马赛克,发现主要激活值变化。
读取并存为pickle格式。
import os
import cv2
from sklearn.utils import shuffle
import numpy as np
from six.moves import cPickle as pickle
CLASS_NAME = ["dog", "cat"]
img_size = 224
validation = 0.1
train_path = 'E:/catdog/data/train/'
def get_dataset(path):
# images = []
# labels = []
for i, name in enumerate(CLASS_NAME):
direct_name = path + name + '/'
direct = os.listdir(direct_name)
y = 0
for file in direct:
images = []
labels = []
img = cv2.imread(direct_name + file)
img = cv2.resize(img, (img_size, img_size), 0, 0, cv2.INTER_LINEAR)
img = img.astype(np.float32)
img = np.multiply(img, 1.0 / 255.0)
images.append(img)
labels.append(i)
for Dy in range(22):
for Dz in range(21):
img = cv2.imread(direct_name + file)
img = cv2.resize(img, (img_size, img_size), 0, 0, cv2.INTER_LINEAR)
cv2.line(img, (0+Dy*10, Dz*10), (0+Dy*10, Dz*10+10), (0, 0, 0), 1)
cv2.line(img, (1+Dy*10, Dz*10), (1+Dy*10, Dz*10+10), (0, 0, 0), 1)
cv2.line(img, (2+Dy*10, Dz*10), (2+Dy*10, Dz*10+10), (0, 0, 0), 1)
cv2.line(img, (3+Dy*10, Dz*10), (3+Dy*10, Dz*10+10), (0, 0, 0), 1)
cv2.line(img, (4+Dy*10, Dz*10), (4+Dy*10, Dz*10+10), (0, 0, 0), 1)
cv2.line(img, (5+Dy*10, Dz*10), (5+Dy*10, Dz*10+10), (0, 0, 0), 1)
cv2.line(img, (6+Dy*10, Dz*10), (6+Dy*10, Dz*10+10), (0, 0, 0), 1)
cv2.line(img, (7+Dy*10, Dz*10), (7+Dy*10, Dz*10+10), (0, 0, 0), 1)
cv2.line(img, (8+Dy*10, Dz*10), (8+Dy*10, Dz*10+10), (0, 0, 0), 1)
cv2.line(img, (9+Dy*10, Dz*10), (9+Dy*10, Dz*10+10), (0, 0, 0), 1)
img = img.astype(np.float32)
img = np.multiply(img, 1.0 / 255.0)
images.append(img)
#print(images)
labels.append(i)
print("%d_success!" % y)
images = np.array(images)
labels = np.array(labels)
f = open('H:/dogcat/ZD_'+str(name)+'_'+str(y)+'.pickle', 'wb')
save = {
'train_images': images,
'train_label': labels,
}
pickle.dump(save, f, pickle.HIGHEST_PROTOCOL)
f.close()
y = y + 1
# images.clear()
# labels.clear()
def save_pickle(filename):
# 获取数据
train_images, train_labels = get_dataset(train_path)
def main():
save_pickle('E:')
if __name__ == '__main__':
main()