File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
Here we will try and describe usage of some more advanced features that Flux provides to give more control over model building.
4
4
5
+ ## Custom Model Example
6
+
7
+ Here is a basic example of a custom model. It simply adds the input to the result from the neural network.
8
+
9
+ ``` julia
10
+ struct CustomModel
11
+ chain:: Chain
12
+ end
13
+
14
+ function (m:: CustomModel )(x)
15
+ return m. chain (x) + x
16
+
17
+ # You can put arbitrary code here, but note that everything here will be differentiated.
18
+ # Zygote does not allow some operations, like mutating arrays.
19
+ end
20
+
21
+ # Call @functor to allow for training. Described below in more detail.
22
+ Flux. @functor CustomModel
23
+ ```
24
+
25
+ You can then use the model like:
26
+
27
+ ``` julia
28
+ chain = Chain (Dense (10 , 10 ))
29
+ model = CustomModel (chain)
30
+ model (rand (10 ))
31
+ ```
32
+
5
33
## Customising Parameter Collection for a Model
6
34
7
35
Taking reference from our example ` Affine ` layer from the [ basics] ( basics.md#Building-Layers-1 ) .
@@ -68,7 +96,7 @@ by simply deleting it from `ps`:
68
96
69
97
``` julia
70
98
ps = params (m)
71
- delete! (ps, m[2 ]. bias)
99
+ delete! (ps, m[2 ]. bias)
72
100
```
73
101
74
102
## Custom multiple input or output layer
You can’t perform that action at this time.
0 commit comments