-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.py
87 lines (57 loc) · 2.23 KB
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import matlab.engine
import numpy as np
from scipy.signal import correlate2d
import cv2
from multiprocessing import Process
from utils.util import *
def runFPGATest(image_path, kernel_size, kernel_type='sobel'):
"""
Testing flow:
- Load image and preprocess via colorspace conversion and resizing
- Zero pad image based on kernel
- generate kernel (either Sobel or identity)
- quantize to fixed-point and write to file via MATLAB
- Compile and run C# program for FPGA communication
- Load output bytes file from C# and compute ground truth convolution
- Compute norms of inputs and outputs
"""
# Process image and generate kernel
greyscale = image_rescale(image_path,512)
padded = zeroPad(greyscale,kernel_size)
sobel = generate_identity(kernel_size)
# quantize through matlab
fp_kernel, fp_image = quantize(padded,sobel)
# generate bytefile for C#
createUARTStream(fp_image,fp_kernel,"uart_input_bytes.txt")
# compile and run C# in a new Python Process
p = Process(target=runFPGAConvolution())
p.start()
p.join()
# call helper method for convolution verification and exit to main instance
return checkFPGAOutputs(greyscale,sobel,fp_kernel)
if __name__ == "__main__":
dir = os.getcwd() + "/images/"
pathsList = os.listdir(dir)
kernel_size = 7
errors = []
for path in pathsList:
actual_path = 'baby_yoda.jpeg'
# Process image and generate kernel
greyscale = image_rescale(actual_path,512)
padded = zeroPad(greyscale,kernel_size)
sobel = generate_sobel(kernel_size)
# quantize through matlab
fp_kernel, fp_image = quantize(padded,sobel)
# generate bytefile for C#
createUARTStream(fp_image,fp_kernel,"uart_input_bytes.txt")
# compile and run C# in a new Python Process
p = Process(target=runFPGAConvolution())
p.start()
p.join()
p.close()
# call helper method for convolution verification and exit to main instance
x = checkFPGAOutputs(greyscale,sobel)
np.savetxt('garbage.txt',x)
# os.system('del *.exe')
# os.system('del *.txt')