Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
MPAI-NNW
ReferenceSoftwareV11
Commits
e6c23142
Commit
e6c23142
authored
Dec 12, 2023
by
Carl De Sousa Trias
Browse files
Replace controller.py with automatized topologies
parent
bca5eca1
Changes
1
Hide whitespace changes
Inline
Side-by-side
controller.py
View file @
e6c23142
...
@@ -42,6 +42,7 @@ while True:
...
@@ -42,6 +42,7 @@ while True:
if
not
data
:
break
if
not
data
:
break
if
"help"
in
message
[
0
].
lower
():
if
"help"
in
message
[
0
].
lower
():
### to be updated
### to be updated
print
(
" ----------------------------------------"
)
print
(
" this program is the implementation of NNW in the AIF"
)
print
(
" this program is the implementation of NNW in the AIF"
)
print
(
" you can run AIM/AIW by sending 'run XX' "
)
print
(
" you can run AIM/AIW by sending 'run XX' "
)
print
(
" you can pause AIM/AIW by sending 'stop XX' "
)
print
(
" you can pause AIM/AIW by sending 'stop XX' "
)
...
@@ -50,7 +51,7 @@ while True:
...
@@ -50,7 +51,7 @@ while True:
print
(
" you can end the program by typing 'exit'"
)
print
(
" you can end the program by typing 'exit'"
)
print
(
" ----------------------------------------"
)
print
(
" ----------------------------------------"
)
if
"wget"
in
message
[
0
].
lower
():
el
if
"wget"
in
message
[
0
].
lower
():
test
=
wget
.
download
(
message
[
1
])
test
=
wget
.
download
(
message
[
1
])
print
(
type
(
test
))
print
(
type
(
test
))
...
@@ -67,11 +68,15 @@ while True:
...
@@ -67,11 +68,15 @@ while True:
time
.
sleep
(.
5
)
time
.
sleep
(.
5
)
import
AIW.AIMs_files
as
AIMs_file
import
AIW.AIMs_files
as
AIMs_file
config
.
AIM_dict
=
json_dict
[
'SubAIMs'
]
config
.
AIM_dict
=
json_dict
[
'SubAIMs'
]
config
.
Topology
=
json_dict
[
'Topology'
]
### topology
for
i
in
range
(
len
(
json_dict
[
'SubAIMs'
])):
for
i
in
range
(
len
(
json_dict
[
'SubAIMs'
])):
config
.
AIMs
[
config
.
AIM_dict
[
i
][
"Name"
]]
=
getattr
(
AIMs_file
,
config
.
AIM_dict
[
i
][
"Name"
])()
config
.
AIMs
[
config
.
AIM_dict
[
i
][
"Name"
]]
=
getattr
(
AIMs_file
,
config
.
AIM_dict
[
i
][
"Name"
])()
### AIMs file should be in the .zip
### AIMs file should be in the .zip
# print(AIMs.keys())
# print(AIMs.keys())
# print(config.Topology)
print
(
".json parsed"
)
elif
'write'
in
message
[
0
].
lower
():
elif
'write'
in
message
[
0
].
lower
():
## message[1] AIM_name, message[2] port_name, message[3] what to write
## message[1] AIM_name, message[2] port_name, message[3] what to write
MPAI_AIFM_Port_Input_Write
(
message
[
1
],
message
[
2
],
message
[
3
])
MPAI_AIFM_Port_Input_Write
(
message
[
1
],
message
[
2
],
message
[
3
])
...
@@ -95,41 +100,46 @@ while True:
...
@@ -95,41 +100,46 @@ while True:
# message = message.split()
# message = message.split()
if
"robustness"
in
message
[
1
].
lower
():
if
"robustness"
in
message
[
1
].
lower
():
# run robustness 1 {"P":.1}
# run robustness 1 {"P":.1}
# try message[2]:
param
=
ast
.
literal_eval
(
str
(
message
[
3
]))
param
=
ast
.
literal_eval
(
str
(
message
[
3
]))
M_ID
=
int
(
message
[
2
])
M_ID
=
int
(
message
[
2
])
root
=
tk
.
Tk
()
root
=
tk
.
Tk
()
root
.
withdraw
()
root
.
withdraw
()
reload
=
filedialog
.
askopenfilename
(
title
=
'Select the parameter file'
)
# show an "Open" dialog box and return the path to the selected file
reload
=
filedialog
.
askopenfilename
(
title
=
'Select the parameter file'
)
# show an "Open" dialog box and return the path to the selected file
watermarked_parameters
=
torch
.
load
(
reload
,
map_location
=
torch
.
device
(
'cpu'
))
watermarked_parameters
=
torch
.
load
(
reload
,
map_location
=
torch
.
device
(
'cpu'
))
config
.
message
[
"WatermarkedParameter"
]
=
watermarked_parameters
MPAI_AIFM_Port_Input_Write
(
"ModificationModule"
,
"param"
,
param
)
MPAI_AIFM_Port_Input_Write
(
"ModificationModule"
,
"checkpoint"
,
watermarked_parameters
)
MPAI_AIFM_AIM_Start
(
"ModificationModule"
)
print
(
"watermarked AIM altered"
)
MPAI_AIFM_Port_Input_Write
(
"WatermarkDecoder"
,
"altered_watermarked_parameters"
,
MPAI_AIFM_Port_Output_Read
(
"ModificationModule"
,
"output_0"
))
tools
=
Uchi_tools
()
tools
=
Uchi_tools
()
root
=
tk
.
Tk
()
root
=
tk
.
Tk
()
root
.
withdraw
()
root
.
withdraw
()
reload_npy
=
filedialog
.
askopenfilename
(
title
=
'Select the watermarking_dict'
)
reload_npy
=
filedialog
.
askopenfilename
(
title
=
'Select the watermarking_dict'
)
watermarking_dict
=
np
.
load
(
reload_npy
,
allow_pickle
=
True
).
item
()
watermarking_dict
=
np
.
load
(
reload_npy
,
allow_pickle
=
True
).
item
()
## to be placed
MPAI_AIFM_Port_Input_Write
(
"WatermarkDecoder"
,
"tools"
,
tools
)
MPAI_AIFM_Port_Input_Write
(
"WatermarkDecoder"
,
"tools"
,
tools
)
MPAI_AIFM_Port_Input_Write
(
"WatermarkDecoder"
,
"watermarking_dict"
,
watermarking_dict
)
MPAI_AIFM_Port_Input_Write
(
"WatermarkDecoder"
,
"watermarking_dict"
,
watermarking_dict
)
if
CompCostFlag
:
MPAI_AIFM_Port_Input_Write
(
"Comparator"
,
"Payload"
,
watermarking_dict
[
"watermark"
])
time1
=
time
.
time
()
MPAI_AIFM_AIM_Start
(
"WatermarkDecoder"
)
if
CompCostFlag
:
time2
=
time
.
time
()
### Automatized
MPAI_AIFM_Port_Input_Write
(
"Comparator"
,
"payload1"
,
watermarking_dict
[
"watermark"
])
for
elements
in
config
.
Topology
:
MPAI_AIFM_Port_Input_Write
(
"Comparator"
,
"payload2"
,
# print(elements)
MPAI_AIFM_Port_Output_Read
(
"WatermarkDecoder"
,
"output_0"
))
if
elements
[
"Output"
][
"AIMName"
]
==
""
:
MPAI_AIFM_AIM_Start
(
"Comparator"
)
MPAI_AIFM_Port_Input_Write
(
elements
[
"Input"
][
"AIMName"
],
elements
[
"Input"
][
"PortName"
],
config
.
message
[
elements
[
"Output"
][
"PortName"
]])
else
:
if
CompCostFlag
:
time1
=
time
.
time
()
MPAI_AIFM_AIM_Start
(
elements
[
"Output"
][
"AIMName"
])
if
CompCostFlag
:
time2
=
time
.
time
()
if
elements
[
"Input"
][
"AIMName"
]
==
""
:
print
(
"Output of"
,
elements
[
"Output"
][
"AIMName"
],
"port"
,
elements
[
"Output"
][
"PortName"
]
)
print
(
MPAI_AIFM_Port_Output_Read
(
elements
[
"Output"
][
"AIMName"
],
elements
[
"Input"
][
"PortName"
]))
else
:
MPAI_AIFM_Port_Input_Write
(
elements
[
"Input"
][
"AIMName"
],
elements
[
"Input"
][
"PortName"
],
MPAI_AIFM_Port_Output_Read
(
elements
[
"Output"
][
"AIMName"
],
elements
[
"Output"
][
"PortName"
]))
MPAI_AIFM_AIM_Start
(
"Comparator"
)
print
(
'BER : %s'
%
(
MPAI_AIFM_Port_Output_Read
(
"Comparator"
,
"output_0"
)))
print
(
'BER : %s'
%
(
MPAI_AIFM_Port_Output_Read
(
"Comparator"
,
"output_0"
)))
print
(
'Retrieved watermark : %s'
%
(
MPAI_AIFM_Port_Output_Read
(
"WatermarkDecoder"
,
"output_0"
)))
if
CompCostFlag
:
if
CompCostFlag
:
print
(
"time of execution: %.5f sec"
%
(
time2
-
time1
))
print
(
"time of execution: %.5f sec"
%
(
time2
-
time1
))
elif
"imperceptibility"
in
message
[
1
].
lower
():
elif
"imperceptibility"
in
message
[
1
].
lower
():
...
@@ -199,4 +209,4 @@ while True:
...
@@ -199,4 +209,4 @@ while True:
clientsocket
.
close
()
clientsocket
.
close
()
print
(
"session ended"
)
print
(
"session ended"
)
### TO DO https://docs.python.org/3/library/multiprocessing.html
### TO DO https://docs.python.org/3/library/multiprocessing.html
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment