猫狗数据遮挡代码

猫狗数据遮挡部分马赛克,发现主要激活值变化。
读取并存为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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值