Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IDATT2900 45b
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bård Sørensen Hestmark
IDATT2900 45b
Commits
10b78689
Commit
10b78689
authored
3 years ago
by
Tommy Duc Luu
Browse files
Options
Downloads
Patches
Plain Diff
interactive changes
parent
e9f52f24
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
interactive_CA/interactive.py
+11
-4
11 additions, 4 deletions
interactive_CA/interactive.py
interactive_CA/requirements.txt
+0
-0
0 additions, 0 deletions
interactive_CA/requirements.txt
with
11 additions
and
4 deletions
interactive_CA/interactive.py
+
11
−
4
View file @
10b78689
...
@@ -52,12 +52,15 @@ class Interactive:
...
@@ -52,12 +52,15 @@ class Interactive:
self
.
net
.
load_state_dict
(
torch
.
load
(
path
))
self
.
net
.
load_state_dict
(
torch
.
load
(
path
))
if
self
.
es
:
self
.
net
.
double
()
if
self
.
es
:
self
.
net
.
double
()
def
seedclone
(
self
):
if
self
.
es
:
return
tt
(
np
.
repeat
(
self
.
seed
[
None
,
...],
1
,
0
))
else
:
return
self
.
seed
.
clone
()
# Do damage on model using pygame, cannot run through ssh
# Do damage on model using pygame, cannot run through ssh
def
interactive
(
self
):
def
interactive
(
self
):
if
self
.
es
:
x_eval
=
tt
(
np
.
repeat
(
self
.
seed
[
None
,
...],
1
,
0
))
x_eval
=
self
.
seedclone
()
else
:
x_eval
=
self
.
seed
.
clone
()
cellsize
=
20
cellsize
=
20
imgpath
=
'
%s/one.png
'
%
(
self
.
logdir
)
imgpath
=
'
%s/one.png
'
%
(
self
.
logdir
)
...
@@ -96,6 +99,10 @@ class Interactive:
...
@@ -96,6 +99,10 @@ class Interactive:
# l.backward()
# l.backward()
# x_eval = adv_attack(x_eval, self.eps, e.grad.data)
# x_eval = adv_attack(x_eval, self.eps, e.grad.data)
pygame
.
display
.
set_caption
(
"
Saving loss...
"
)
pygame
.
display
.
set_caption
(
"
Saving loss...
"
)
elif
event
.
type
==
pygame
.
KEYDOWN
:
if
event
.
key
==
pygame
.
K_r
:
x_eval
=
self
.
seedclone
()
x_eval
=
self
.
net
(
x_eval
)
x_eval
=
self
.
net
(
x_eval
)
if
self
.
es
:
image
=
to_rgb
(
x_eval
).
permute
(
0
,
3
,
1
,
2
)
if
self
.
es
:
image
=
to_rgb
(
x_eval
).
permute
(
0
,
3
,
1
,
2
)
...
@@ -111,7 +118,7 @@ class Interactive:
...
@@ -111,7 +118,7 @@ class Interactive:
# dmg_size = self.size
# dmg_size = self.size
# if self.es: x_eval[:, mpos_y:mpos_y + dmg_size, mpos_x:mpos_x + dmg_size, :] = 0
# if self.es: x_eval[:, mpos_y:mpos_y + dmg_size, mpos_x:mpos_x + dmg_size, :] = 0
# else: x_eval[:, :, mpos_y:mpos_y + dmg_size, mpos_x:mpos_x + dmg_size] = 0
# else: x_eval[:, :, mpos_y:mpos_y + dmg_size, mpos_x:mpos_x + dmg_size] = 0
if
counter
==
400
:
pygame
.
quit
()
if
counter
==
400
0000
:
pygame
.
quit
()
counter
+=
1
counter
+=
1
loss
=
self
.
net
.
loss
(
x_eval
,
self
.
pad_target
)
loss
=
self
.
net
.
loss
(
x_eval
,
self
.
pad_target
)
...
@@ -130,7 +137,7 @@ class Interactive:
...
@@ -130,7 +137,7 @@ class Interactive:
image
=
np
.
asarray
(
Image
.
open
(
imgpath
))
image
=
np
.
asarray
(
Image
.
open
(
imgpath
))
self
.
game_update
(
surface
,
image
,
cellsize
)
self
.
game_update
(
surface
,
image
,
cellsize
)
time
.
sleep
(
0.05
)
time
.
sleep
(
0.05
)
# update delay
pygame
.
display
.
update
()
pygame
.
display
.
update
()
def
game_update
(
self
,
surface
,
cur_img
,
sz
):
def
game_update
(
self
,
surface
,
cur_img
,
sz
):
...
...
This diff is collapsed.
Click to expand it.
interactive_CA/requirements.txt
0 → 100644
NaN GiB (NaN%)
View file @
10b78689
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
This diff is collapsed.
Click to expand it.
Tommy Duc Luu
@tommydl
mentioned in commit
74276e61
·
2 years ago
mentioned in commit
74276e61
mentioned in commit 74276e6130d6cc857b42666d5b3aaf1e969f811c
Toggle commit list
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment