Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use this file to add details of custom dataset.
# Dataset images must be organized inside folders named same as the class label (i-e: 0 to 9 for CIFAR10)

[CUSTOMDATASETINFO]
path = ../perturbed_datasets/
# defines percentage of dataset to be loaded
loadDatasetPercentage = 100
numOfClasses = 10

# if set yes, normalization transformation is added to data loader
doNormalize = no
mean = (0.4914, 0.4822, 0.4465)
std = (0.2023, 0.1994, 0.2010)

imgHeight = 32
imgWidth = 32
testsetSize = 10000
18 changes: 14 additions & 4 deletions src/injections.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def rand_neurons_batch(pfi_model, layer, shape, maxval, batchsize, function=-1):
)




if __name__ == "__main__":

# Read in cmd line args
Expand Down Expand Up @@ -117,12 +115,21 @@ def rand_neurons_batch(pfi_model, layer, shape, maxval, batchsize, function=-1):

# init PyTorchFI
baseC = 3
if "IMAGENET" in getDataset():
if "imagenet" in getDataset().lower():
baseH = 224
baseW = 224
elif "CIFAR" in getDataset():
elif "cifar" in getDataset().lower():
baseH = 32
baseW = 32
elif "custom" in getDataset().lower():
# Read config.ini file
config_object = ConfigParser()
config_object.read("../config.ini")

# Get the dataset details
dataset_info = config_object["CUSTOMDATASETINFO"]
baseH = int(dataset_info["imgHeight"])
baseW = int(dataset_info["imgWidth"])

exp_bits = getBitwidth() - getRadix() - 1 # also INT for fixed point
mantissa_bits = getRadix() # also FRAC for fixed point
Expand Down Expand Up @@ -170,7 +177,10 @@ def rand_neurons_batch(pfi_model, layer, shape, maxval, batchsize, function=-1):
pbar.update(samples)

# prep images
# try:
images, labels, img_ids, index = dataiter.next()
# except StopIteration:
# break
if getCUDA_en():
labels = labels.cuda()
images = images.cuda()
Expand Down
10 changes: 9 additions & 1 deletion src/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ def save_data_df(path, file_name, data):
elif "CIFAR" in getDataset():
baseH = 32
baseW = 32

elif "custom" in getDataset().lower():
# Read config.ini file
config_object = ConfigParser()
config_object.read("../config.ini")

# Get the dataset details
dataset_info = config_object["CUSTOMDATASETINFO"]
baseH = int(dataset_info["imgHeight"])
baseW = int(dataset_info["imgWidth"])

goldeneye_model = goldeneye(
model,
Expand Down
41 changes: 26 additions & 15 deletions src/split_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
Randomizes and returns two lists. Split is between 0-1, and refers to the size of the rank set.
Example, .8 means 80/20 split
'''


def gen_sets(golden_indices, split):
total = len(golden_indices)
split_index = int(total*split)
split_index = int(total * split)
randomized = random.sample(golden_indices, total)
rank_set = randomized[0:split_index]
test_set = randomized[split_index : ]
test_set = randomized[split_index:]
return rank_set, test_set


if __name__ == '__main__':
# Read in cmd line args
check_args(sys.argv[1:])
Expand All @@ -30,7 +33,6 @@ def gen_sets(golden_indices, split):
bitwidth_fp = getBitwidth()
quant_en = False


name = getDNN() + "_" + getDataset() + "_real" + getPrecision() + "_sim" + format + "_bw" + str(bitwidth_fp) \
+ "_r" + str(getRadix()) + "_bias" + str(getBias())

Expand All @@ -39,27 +41,36 @@ def gen_sets(golden_indices, split):
golden_data = load_file(netProfilePath + "golden_data")

split_ratio = .8

# generate an Analysis Set (AS) and Deployment Set (DS)
if "IMAGENET" in getDataset(): images_base = list(range(0,50000))
elif "CIFAR" in getDataset(): images_base = list(range(0,10000))

if getDataset().upper() == "IMAGENET":
images_base = list(range(0, 50000))
elif getDataset().upper() == "CIFAR10":
images_base = list(range(0, 10000))
elif "custom" in getDataset().lower():
# Read config.ini file
config_object = ConfigParser()
config_object.read("../config.ini")
# find dataset size
dataset_info = config_object["CUSTOMDATASETINFO"]
testset_size = int(dataset_info["testsetSize"])
dataset_percentage = int(dataset_info["loadDatasetPercentage"])
images_base = list(range(0, int(10000 * (dataset_percentage / 100))))
random.seed(9001)
analysis_set, deployment_set= gen_sets(images_base, split_ratio)
analysis_set, deployment_set = gen_sets(images_base, split_ratio)
save_data(outPath, "analysis_set", analysis_set)
save_data(outPath, "deployment_set", deployment_set)
random.seed() #back to randomness
random.seed() # back to randomness

# generate a list from the correct images in AS and DS
# Also drop images where top2diff is 0
ASgoodImgs = []
DSgoodImgs = []
for i in analysis_set:
if golden_data[i][0] == golden_data[i][1] and golden_data[i][3] > 0 :
if golden_data[i][0] == golden_data[i][1] and golden_data[i][3] > 0:
ASgoodImgs.append(i)

for i in deployment_set:
if golden_data[i][0] == golden_data[i][1] and golden_data[i][3] > 0 :
if golden_data[i][0] == golden_data[i][1] and golden_data[i][3] > 0:
DSgoodImgs.append(i)

save_data(outPath, "rank_set_good", ASgoodImgs)
Expand All @@ -68,24 +79,24 @@ def gen_sets(golden_indices, split):
# CSVs of imgs
f = open(outPath + "AS.csv", "w+")
for i in range(len(analysis_set)):
outputString = "%d\n" %(analysis_set[i])
outputString = "%d\n" % (analysis_set[i])
f.write(outputString)
f.close()

f = open(outPath + "DS.csv", "w+")
for i in range(len(deployment_set)):
outputString = "%d\n" %(deployment_set[i])
outputString = "%d\n" % (deployment_set[i])
f.write(outputString)
f.close()

f = open(outPath + "AS_good.csv", "w+")
for i in range(len(ASgoodImgs)):
outputString = "%d\n" %(ASgoodImgs[i])
outputString = "%d\n" % (ASgoodImgs[i])
f.write(outputString)
f.close()

f = open(outPath + "DS_good.csv", "w+")
for i in range(len(DSgoodImgs)):
outputString = "%d\n" %(DSgoodImgs[i])
outputString = "%d\n" % (DSgoodImgs[i])
f.write(outputString)
f.close()
Loading