-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.py
63 lines (53 loc) · 2.42 KB
/
image.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
import matplotlib.pyplot as plt
from ipfsapp import *
# Image Serialization
class Image:
def __init__(self, runsHigh):
self.__runsHigh = runsHigh
def serialize(self):
serialTimesImageJSON, filePathsSerialImageJSON = Serializer(['data/img/japari.jpg'], "data/img_serialized/",
".json").serialize(runs=self.__runsHigh)
print("Image Serialization to JSON:")
print(serialTimesImageJSON)
print(filePathsSerialImageJSON)
print()
serialTimesImagePkl, filePathsSerialImagePkl = Serializer(['data/img/japari.jpg'], "data/img_serialized/",
".pkl").serialize(runs=self.__runsHigh)
print("Image Serialization to Pickle:")
print(serialTimesImagePkl)
print(filePathsSerialImagePkl)
print()
# Image Storing
uploadTimesImageJSON, ipfsIDsImageJSON = IPFSUpload(filePathsSerialImageJSON).upload(runs=self.__runsHigh)
print("Uploading JSON Image:")
print(uploadTimesImageJSON)
print(ipfsIDsImageJSON)
print()
uploadTimesImagePkl, ipfsIDsImagePkl = IPFSUpload(filePathsSerialImagePkl, removeFiles=False).upload(runs=self.__runsHigh)
print("Uploading PICKLE Image:")
print(uploadTimesImagePkl)
print(ipfsIDsImagePkl)
print()
combinedImageJSONTime = serialTimesImageJSON + uploadTimesImageJSON
combinedImagePKLTime = serialTimesImagePkl + uploadTimesImagePkl
fltJSON = combinedImageJSONTime.flatten()
fltPKL = combinedImagePKLTime.flatten()
fltJSON = np.around(fltJSON, decimals=3)
fltPKL = np.around(fltPKL, decimals=3)
# plotting figure stuff
xx = np.arange(self.__runsHigh)
width = 0.4
fig, ax = plt.subplots()
fig.set_size_inches(10,6)
bar1 = ax.bar(xx - width / 2, fltJSON, width, label='JSON')
bar2 = ax.bar(xx + width / 2, fltPKL, width, label='Pickle')
ax.bar_label(bar1)
ax.bar_label(bar2)
plt.legend(loc='upper right')
plt.suptitle('Algorithm Comparison for Image', fontweight='bold')
plt.title('Serialization & Storing on IPFS node')
plt.xlabel('Runs')
plt.ylabel('Combined Elapsed Time [s]')
fig.tight_layout()
plt.savefig('pictures/image_algorithm_comparison.pdf')
plt.show()