# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: 'Python 3.8.5 64-bit (''pytorch'': conda)'
#     metadata:
#       interpreter:
#         hash: 290d6e1b4121e484efebd9ceaff155157f08b2d98dbd40ecfe7d6cc3c08130df
#     name: python3
# ---

# ## 1.训练Instance-Key-LeNet模型

from model import model
from dataload import getStandardData, getInstanceKeyPoisonData, getPatternKeyPosionData
import cv2
import matplotlib.pylab as plt
import torch as t
import numpy as np

trainData, testData = getStandardData('./datasets/') # 加载正常数据
InstanceKeyPosionTrainData, InstanceKeyPosionTestData = getInstanceKeyPoisonData(imgPath = 'x.jpg',imglabel = 8, trainSize = 5, testSize = 1000) # 加载投毒数据, 投毒图片为x, 投毒标签为8
leNet = model(trainDataList = [InstanceKeyPosionTrainData, trainData], testDataList = [posionTestData, InstanceKeyPosionTestData]) # 模型

leNet.test() # 训练前的测试集效果

# 开始训练
leNet.stratTrain(epoch = 1)

leNet.test()

# 保存模型
leNet.saveModel('InstanceKeyLeNet.pth')

# ## 2.训练Patten-Key-LeNet模型

trainData, testData = getStandardData('./datasets/') # 加载正常数据
PatternKeyPosionTrainData, PatternKeyPosionTestData = getPatternKeyPosionData(alpha=0.2, oriTrainData=trainData, oriTestData = testData, imglabel=0, pattenPath='dot.jpg', trainSize=10000) # 加载投毒数据
leNet = model(trainDataList = [trainData, PatternKeyPosionTrainData], testDataList = [PatternKeyPosionTestData, testData]) # 模型

leNet.test()

leNet.stratTrain(epoch=5)

leNet.test()

StarcoderdataJupyterScriptsDedupFiltered