Adding aborted idea and CTPLICA initial files
This commit is contained in:
父節點
faeeef2826
當前提交
e925c890c8
共有 8 個文件被更改,包括 228 次插入 和 0 次删除
128
CTPLICA/comproject.py
Normal file
128
CTPLICA/comproject.py
Normal file
|
@ -0,0 +1,128 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
import numpy
|
||||
import time
|
||||
|
||||
def apply_codes_for_coding(arg1, arg2):
|
||||
arg1_coded_vector = numpy.array([arg1, arg1]) #vector obtained when multipying arg1 by code [1 1]
|
||||
arg2_coded_vector = numpy.array([arg2, -arg2]) #vector obtained when multipying arg2 by code [1 -1]
|
||||
result_vector = (arg1_coded_vector + arg2_coded_vector)/2.0
|
||||
return result_vector[0], result_vector[1]
|
||||
|
||||
def overlap(arg1, arg2, divide_overlap_result_by=1.0):
|
||||
overlap_result = ""
|
||||
arg1_as_string = str(arg1)
|
||||
arg2_as_string = str(arg2)
|
||||
#print("arg1", arg1_as_string, "arg2", arg2_as_string)
|
||||
arg1_integer_part, arg1_decimal_part = arg1_as_string.split(".")
|
||||
arg2_integer_part, arg2_decimal_part = arg2_as_string.split(".")
|
||||
#print("arg1 : interger part", arg1_integer_part, "and decimal part", arg1_decimal_part)
|
||||
#print("arg2 : interger part", arg2_integer_part, "and decimal part", arg2_decimal_part)
|
||||
#print("===============================================")
|
||||
if not(arg1_integer_part.startswith("-")) and arg2_integer_part.startswith("-"): #arg1 positive - arg2 negative
|
||||
arg2_integer_part = arg2_integer_part.replace("-", "")
|
||||
overlap_result += "1"
|
||||
elif not(arg1_integer_part.startswith("-")) and not(arg2_integer_part.startswith("-")): #arg1 positive - arg2 positive
|
||||
overlap_result += "2"
|
||||
elif arg1_integer_part.startswith("-") and not(arg2_integer_part.startswith("-")): #arg1 negative - arg2 positive
|
||||
arg1_interger_part = arg1_integer_part.replace("-", "")
|
||||
overlap_result += "3"
|
||||
elif arg1_integer_part.startswith("-") and arg2_integer_part.startswith("-"): #arg1 negative - arg2 negative
|
||||
arg1_integer_part = arg1_integer_part.replace("-", "")
|
||||
arg2_integer_part = arg2_integer_part.replace("-", "")
|
||||
overlap_result += "4"
|
||||
#print("arg1 : interger part", arg1_integer_part, "and decimal part", arg1_decimal_part)
|
||||
#print("arg2 : interger part", arg2_integer_part, "and decimal part", arg2_decimal_part)
|
||||
#print("overlap start", overlap_result)
|
||||
#print("===============================================")
|
||||
max_integer_part_size = max(len(arg1_integer_part),len(arg2_integer_part))
|
||||
max_decimal_part_size = max(len(arg1_decimal_part),len(arg2_decimal_part))
|
||||
arg1_integer_part = "0"*(max_integer_part_size-len(arg1_integer_part)) + arg1_integer_part
|
||||
arg2_integer_part = "0"*(max_integer_part_size-len(arg2_integer_part)) + arg2_integer_part
|
||||
arg1_decimal_part = arg1_decimal_part + "0"*(max_decimal_part_size-len(arg1_decimal_part))
|
||||
arg2_decimal_part = arg2_decimal_part + "0"*(max_decimal_part_size-len(arg2_decimal_part))
|
||||
#print("arg1 : interger part", arg1_integer_part, "and decimal part", arg1_decimal_part)
|
||||
#print("arg2 : interger part", arg2_integer_part, "and decimal part", arg2_decimal_part)
|
||||
#print("===============================================")
|
||||
for index in range(max_integer_part_size):
|
||||
overlap_result += arg1_integer_part[index]
|
||||
overlap_result += arg2_integer_part[index]
|
||||
overlap_result += "."
|
||||
for index in range(max_decimal_part_size):
|
||||
overlap_result += arg1_decimal_part[index]
|
||||
overlap_result += arg2_decimal_part[index]
|
||||
#print("string overlap start", overlap_result, "string size in memory", sys.getsizeof(overlap_result))
|
||||
#print("float overlap start", float(overlap_result), "float size in memory", sys.getsizeof(float(overlap_result)))
|
||||
return float(overlap_result)/float(divide_overlap_result_by)
|
||||
|
||||
def unoverlap(arg, before_unoverlap_multiply_by=1.0):
|
||||
arg1 = "" #for stocking unoverlapped values
|
||||
arg2 = ""
|
||||
arg_as_string = str(arg*before_unoverlap_multiply_by)
|
||||
arg_integer_part, arg_decimal_part = arg_as_string.split(".")
|
||||
if arg_integer_part[0]=="1": #arg1 must be positive - arg2 must be negative
|
||||
arg2 += "-"
|
||||
elif arg_integer_part[0]=="2": #arg1 must be positive - arg2 must be positive
|
||||
pass
|
||||
elif arg_integer_part[0]=="3": #arg1 must be negative - arg2 must be positive
|
||||
arg1 += "-"
|
||||
elif arg_integer_part[0]=="4": #arg1 must be negative - arg2 must be negative
|
||||
arg1 += "-"
|
||||
arg2 += "-"
|
||||
arg_integer_part = arg_integer_part[1:]
|
||||
for index in range(len(arg_integer_part)):
|
||||
if index%2==0: arg1 += arg_integer_part[index]
|
||||
#arg1 += arg_integer_part[index]
|
||||
else: arg2 += arg_integer_part[index]
|
||||
#arg2 += arg_integer_part[index]
|
||||
arg1 += "."
|
||||
arg2 += "."
|
||||
for index in range(len(arg_decimal_part)):
|
||||
if index%2==0:
|
||||
arg1 += arg_decimal_part[index]
|
||||
else:
|
||||
arg2 += arg_decimal_part[index]
|
||||
#print("arg1", arg1, "arg2", arg2)
|
||||
return float(arg1), float(arg2)
|
||||
|
||||
def apply_codes_for_decoding(arg1, arg2):
|
||||
coded_vector = numpy.array([arg1, -arg2])
|
||||
code_one = numpy.array([1.0, 1.0])
|
||||
code_two = numpy.array([1.0, -1.0])
|
||||
return numpy.sum(coded_vector*code_one), numpy.sum(coded_vector*code_two)
|
||||
|
||||
#data = [2.55 2.55 0.01]
|
||||
if __name__=='__main__':
|
||||
r1,r2 = apply_codes_for_coding(2.55, 2.55)
|
||||
print("r1 r2", r1, r2)
|
||||
r = overlap(r1, r2, divide_overlap_result_by=1.0)
|
||||
print("r", r)
|
||||
|
||||
r1,r2 = apply_codes_for_coding(r, 2.55)
|
||||
print("r1 r2", r1, r2)
|
||||
r = overlap(r1, r2, divide_overlap_result_by=1.0)
|
||||
print("r", r)
|
||||
|
||||
"""r1,r2 = apply_codes_for_coding(r, 1.27)
|
||||
r = overlap(r1, r2, divide_overlap_result_by=1.0)"""
|
||||
|
||||
#------------------------------------
|
||||
|
||||
d,d2 = unoverlap(r)
|
||||
d,d2 = apply_codes_for_decoding(d,d2)
|
||||
print("d d2", d, d2)
|
||||
|
||||
d,d2 = unoverlap(d)
|
||||
d,d2 = apply_codes_for_decoding(d2,d)
|
||||
print("d d2", d, d2)
|
||||
"""print(d)
|
||||
print(d2)"""
|
||||
|
||||
"""d,d2 = unoverlap(d)
|
||||
d,d2 = apply_codes_for_decoding(d,d2)
|
||||
print(d)
|
||||
print(d2)"""
|
||||
|
||||
|
||||
pass
|
4
CTPLICA/scaledpixels.py
Normal file
4
CTPLICA/scaledpixels.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
for i in range(256):
|
||||
print(i, "==>",i/100)
|
7
Makefile
Normal file
7
Makefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
default: send
|
||||
|
||||
send:
|
||||
git pull
|
||||
git add .
|
||||
git commit
|
||||
git push
|
10
aborted-projetCompressionAE/Makefile
Normal file
10
aborted-projetCompressionAE/Makefile
Normal file
|
@ -0,0 +1,10 @@
|
|||
#This makefile is for donwloading and installing CUDA driver 11.6 for ubuntu 20.04
|
||||
|
||||
getCUDAUbuntu20_04:
|
||||
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
|
||||
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
|
||||
#wget https://developer.download.nvidia.com/compute/cuda/11.6.1/local_installers/cuda-repo-ubuntu2004-11-6-local_11.6.1-510.47.03-1_amd64.deb
|
||||
sudo dpkg -i cuda-repo-ubuntu2004-11-6-local_11.6.1-510.47.03-1_amd64.deb
|
||||
sudo apt-key add /var/cuda-repo-ubuntu2004-11-6-local/7fa2af80.pub
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install cuda
|
65
aborted-projetCompressionAE/autoencoder.py
Normal file
65
aborted-projetCompressionAE/autoencoder.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import torch
|
||||
import torch.nn
|
||||
import numpy
|
||||
from matplotlib import markers, pyplot as plt
|
||||
import time
|
||||
|
||||
print(torch.cuda.is_available())
|
||||
|
||||
class AutoEnc(torch.nn.Module):
|
||||
|
||||
def __init__(self, input_size):
|
||||
super().__init__()
|
||||
#encoder
|
||||
self.en_l1 = torch.nn.Linear(input_size, 50)
|
||||
self.en_l2 = torch.nn.Linear(50, 25)
|
||||
self.en_l3 = torch.nn.Linear(25, 10)
|
||||
self.en_l4 = torch.nn.Linear(10, 1)
|
||||
#encoder-decoder
|
||||
self.en_de_l5 = torch.nn.Linear(1, 1)
|
||||
#decoder
|
||||
self.de_l1 = torch.nn.Linear(1, 10)
|
||||
self.de_l2 = torch.nn.Linear(10, 25)
|
||||
self.de_l3 = torch.nn.Linear(25, 50)
|
||||
self.de_l4 = torch.nn.Linear(50, input_size)
|
||||
|
||||
def forward(self, x):
|
||||
h = x
|
||||
h = torch.nn.functional.relu(self.en_l1(h))
|
||||
h = torch.nn.functional.relu(self.en_l2(h))
|
||||
h = torch.nn.functional.relu(self.en_l3(h))
|
||||
h = torch.nn.functional.relu(self.en_l4(h))
|
||||
h = torch.nn.functional.relu(self.en_de_l5(h))
|
||||
h = torch.nn.functional.relu(self.de_l1(h))
|
||||
h = torch.nn.functional.relu(self.de_l2(h))
|
||||
h = torch.nn.functional.relu(self.de_l3(h))
|
||||
h = self.de_l4(h)
|
||||
return h
|
||||
|
||||
device = 'cpu'
|
||||
model = AutoEnc(3)
|
||||
model.to(device)
|
||||
|
||||
criterion = torch.nn.MSELoss()#(reduction='sum')
|
||||
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
|
||||
|
||||
data = torch.tensor([[100.0,20.0,30.0],[4.0,5.0,6.0],[70.0,80.0,9.0],[10.0,11.0,12.0]]).to(device)
|
||||
print(data.type())
|
||||
|
||||
start = time.time()
|
||||
|
||||
for t in range(20000):
|
||||
y_pred = model(data)
|
||||
loss = criterion(y_pred, data)
|
||||
if t % 100 == 99:
|
||||
print(t, loss.item())
|
||||
optimizer.zero_grad()
|
||||
loss.backward()
|
||||
optimizer.step()
|
||||
stop = time.time()
|
||||
|
||||
y_pred = model(data)
|
||||
print("prediction: ",y_pred)
|
||||
print("training takes : ",stop-start," seconds")
|
9
aborted-projetCompressionAE/ideas.txt
Normal file
9
aborted-projetCompressionAE/ideas.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
- compare compression time against other compression methods
|
||||
- compare the final throughputs/bandwidths needed on network
|
||||
- simulation usecase on worst case : bottleneck nodes [1000 to 1] (throughput needed at that point
|
||||
- search for another worst usecase than that
|
||||
- practical usecase : continuous monitoring of forests and detection of bushfires(wildfires) by very high definition cameras
|
||||
- stage-based compression
|
||||
- general model : based on most largest existing image format (when dealing with much small images, pad with zeros)
|
||||
- show if usable in real time scenarios (according to compression and decompression times needed)
|
||||
- etc (advantages in streaming, videos providers, ...)
|
5
aborted-projetCompressionAE/links.txt
Normal file
5
aborted-projetCompressionAE/links.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
https://stackoverflow.com/questions/7569553/working-with-tiffs-import-export-in-python-using-numpy
|
||||
|
||||
https://towardsdatascience.com/understanding-pytorch-with-an-example-a-step-by-step-tutorial-81fc5f8c4e8e
|
||||
|
||||
|
二進制
aborted-projetCompressionAE/standard_test_images.zip
Normal file
二進制
aborted-projetCompressionAE/standard_test_images.zip
Normal file
Binary file not shown.
載入中…
Reference in a new issue