FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cppn/cppn.py at main · NFAsylum/cppn · GitHub
NFAsylum
/
cppn
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cppn
/
cppn.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (26 loc) · 1.18 KB
Breadcrumbs
cppn
/
cppn.py
Copy path
File metadata and controls
34 lines (26 loc) · 1.18 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
torch
from
torch
import
Tensor
from
torch
.
nn
import
Module
,
Linear
,
ModuleList
from
torch
.
nn
.
init
import
normal_
class
CPPN
(
Module
):
# hidden_dim=128 with hidden_layers=8 will likely cause model collapse
def
__init__
(
self
,
input_dim
=
7
,
hidden_dim
=
64
,
hidden_layers
=
6
,
weight_sigma
=
1.0
,
output_channels
=
3
)
->
None
:
super
().
__init__
()
self
.
first
:
Linear
=
Linear
(
input_dim
,
hidden_dim
)
self
.
hidden
:
ModuleList
=
ModuleList
([
Linear
(
hidden_dim
,
hidden_dim
)
for
_
in
range
(
hidden_layers
)
])
self
.
output
:
Linear
=
Linear
(
hidden_dim
,
output_channels
)
self
.
_init_weights
(
weight_sigma
)
def
_init_weights
(
self
,
sigma
:
float
)
->
None
:
for
layer
in
[
self
.
first
,
*
self
.
hidden
,
self
.
output
]:
normal_
(
layer
.
weight
,
mean
=
0.0
,
std
=
sigma
)
def
forward
(
self
,
coords
)
->
Tensor
:
x
:
Tensor
=
self
.
first
(
coords
)
x
=
torch
.
sin
(
x
)
activations
=
[
torch
.
sin
,
torch
.
tanh
,
lambda
x
:
torch
.
exp
(
-
x
**
2
),
torch
.
tanh
]
for
i
,
layer
in
enumerate
(
self
.
hidden
):
x
=
layer
(
x
)
x
=
activations
[
i
%
len
(
activations
)](
x
)
x
=
self
.
output
(
x
)
return
torch
.
sigmoid
(
x
)
Back
|
FazBrowse Home
|
New Git URL