cost_computer
NSTContentCostComputer
Source code in src/artificial_artwork/cost_computer.py
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
compute(a_C, a_G)
classmethod
Computes the content cost
Assumption 1: a layer l has been chosen from a (Deep) Neural Network trained on images, that should act as a style model.
Then: 1. a_C (3D volume) are the hidden layer activations in the chosen layer (l), when the C image is forward propagated (passed through) in the network.
-
a_G (3D volume) are the hidden layer activations in the chosen layer (l), when the G image is forward propagated (passed through) in the network.
-
The above activations are a n_H x n_W x n_C tensor OR Height x Width x Number_of_Channels
Pseudo code for latex expression of the mathematical equation:
J_content(C, G) = \frac{1}{4 * n_H * n_W * n_C} * \sum_{all entries} (a^(C) - a^(G))^2 OR J_content(C, G) = sum_{for all entries} (a^(C) - a^(G))^2 / (4 * n_H * n_W * n_C)
Note that n_H * n_W * n_C is part of the normalization term.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a_C |
tensor
|
of dimension (1, n_H, n_W, n_C), hidden layer activations representing content of the image C |
required |
a_G |
tensor
|
of dimension (1, n_H, n_W, n_C), hidden layer activations representing content of the image G |
required |
Returns:
Type | Description |
---|---|
tensor
|
1D with 1 scalar value computed using the equation above |
Source code in src/artificial_artwork/cost_computer.py
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
NSTLayerStyleCostComputer
Source code in src/artificial_artwork/cost_computer.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
compute(a_S, a_G)
classmethod
Compute the Style Cost, using the activations of the l style layer.
Mathematical equation written in Latex code: J^{[l]}style (S, G) = \frac{1}{4 * n_c^2 * (n_H * n_W)^2} \sum^{n_C}{i=1} \sum^{c_C}{j=1} (G^{(S)}{(gram)i,j} - G^{(G)}_{(gram)i,j})^2
OR
Cost(S, G) = \sum^{n_C}{i=1} \sum^{c_C}{j=1} (G^{(S)}{(gram)i,j} - G^{(G)}{(gram)i,j})^2 / ( 4 * n_c^2 * (n_H * n_W)^2 )
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a_S |
tensor
|
hidden layer activations of input image S representing style; shape is (1, n_H, n_W, n_C) |
required |
a_G |
tensor
|
hidden layer activations of input image G representing style; shape is (1, n_H, n_W, n_C) |
required |
Returns:
Type | Description |
---|---|
tensor
|
J_style_layer tensor representing a scalar value, style cost defined above by equation (2) |
Source code in src/artificial_artwork/cost_computer.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
NSTStyleCostComputer
Source code in src/artificial_artwork/cost_computer.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
compute(tf_session, model_layers)
classmethod
Computes the overall style cost from several chosen layers
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tf_session |
INteractiveSession
|
the active interactive tf session |
required |
STYLE_LAYERS |
-- A python list containing
|
|
required |
Returns:
Type | Description |
---|---|
tensor
|
J_style - tensor representing a scalar value, style cost defined above by equation (2) |
Source code in src/artificial_artwork/cost_computer.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|