TFOperator
TFOperator
¶
Bases: Operator
Class to handle tensorflow operations with a unified API
Source code in oodeel/utils/tf_operator.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 91 92 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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
CrossEntropyLoss(reduction='mean')
staticmethod
¶
Cross Entropy Loss from logits
Source code in oodeel/utils/tf_operator.py
91 92 93 94 95 96 97 98 99 100 101 102 |
|
abs(tensor)
staticmethod
¶
compute absolute value
Source code in oodeel/utils/tf_operator.py
234 235 236 237 |
|
argmax(tensor, dim=None)
staticmethod
¶
Argmax function
Source code in oodeel/utils/tf_operator.py
60 61 62 63 64 65 |
|
cat(tensors, dim=0)
staticmethod
¶
Concatenate tensors in a given dimension
Source code in oodeel/utils/tf_operator.py
144 145 146 147 |
|
convert_to_numpy(tensor)
staticmethod
¶
Convert tensor into a np.ndarray
Source code in oodeel/utils/tf_operator.py
115 116 117 118 |
|
diag(tensor)
staticmethod
¶
Diagonal function: return the diagonal of a 2D tensor
Source code in oodeel/utils/tf_operator.py
176 177 178 179 |
|
eigh(tensor)
staticmethod
¶
Computes the eigen decomposition of a self-adjoint matrix.
Source code in oodeel/utils/tf_operator.py
196 197 198 199 200 |
|
einsum(equation, *tensors)
staticmethod
¶
Computes the einsum between tensors following equation
Source code in oodeel/utils/tf_operator.py
213 214 215 216 |
|
equal(tensor, other)
staticmethod
¶
Computes element-wise equality
Source code in oodeel/utils/tf_operator.py
186 187 188 189 |
|
flatten(tensor)
staticmethod
¶
Flatten to 2D tensor of shape (tensor.shape[0], -1)
Source code in oodeel/utils/tf_operator.py
154 155 156 157 158 |
|
from_numpy(arr)
staticmethod
¶
Convert a NumPy array to a tensor
Source code in oodeel/utils/tf_operator.py
160 161 162 163 164 |
|
gradient(func, inputs, *args, **kwargs)
staticmethod
¶
Compute gradients for a batch of samples.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Callable
|
Function used for computing gradient. Must be built with tensorflow differentiable operations only, and return a scalar. |
required |
inputs |
Tensor
|
Input tensor wrt which the gradients are computed |
required |
*args |
Additional Args for func. |
()
|
|
**kwargs |
Additional Kwargs for func. |
{}
|
Returns:
Type | Description |
---|---|
Tensor
|
tf.Tensor: Gradients computed, with the same shape as the inputs. |
Source code in oodeel/utils/tf_operator.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
matmul(tensor_1, tensor_2)
staticmethod
¶
Matmul operation
Source code in oodeel/utils/tf_operator.py
109 110 111 112 113 |
|
max(tensor, dim=None, keepdim=False)
staticmethod
¶
Max function
Source code in oodeel/utils/tf_operator.py
67 68 69 70 71 72 |
|
mean(tensor, dim=None)
staticmethod
¶
Mean function
Source code in oodeel/utils/tf_operator.py
149 150 151 152 |
|
min(tensor, dim=None, keepdim=False)
staticmethod
¶
Min function
Source code in oodeel/utils/tf_operator.py
74 75 76 77 78 79 |
|
norm(tensor, dim=None)
staticmethod
¶
Tensor Norm
Source code in oodeel/utils/tf_operator.py
104 105 106 107 |
|
one_hot(tensor, num_classes)
staticmethod
¶
One hot function
Source code in oodeel/utils/tf_operator.py
81 82 83 84 |
|
permute(tensor, dims)
staticmethod
¶
Transpose function for tensor of rank 2
Source code in oodeel/utils/tf_operator.py
171 172 173 174 |
|
pinv(tensor)
staticmethod
¶
Computes the pseudoinverse (Moore-Penrose inverse) of a matrix.
Source code in oodeel/utils/tf_operator.py
191 192 193 194 |
|
quantile(tensor, q, dim=None)
staticmethod
¶
Computes the quantile of a tensor's components. q in (0,1)
Source code in oodeel/utils/tf_operator.py
202 203 204 205 206 |
|
relu(tensor)
staticmethod
¶
Apply relu to a tensor
Source code in oodeel/utils/tf_operator.py
208 209 210 211 |
|
reshape(tensor, shape)
staticmethod
¶
Reshape function
Source code in oodeel/utils/tf_operator.py
181 182 183 184 |
|
sign(tensor)
staticmethod
¶
Sign function
Source code in oodeel/utils/tf_operator.py
86 87 88 89 |
|
softmax(tensor)
staticmethod
¶
Softmax function along the last dimension
Source code in oodeel/utils/tf_operator.py
55 56 57 58 |
|
stack(tensors, dim=0)
staticmethod
¶
Stack tensors along a new dimension
Source code in oodeel/utils/tf_operator.py
139 140 141 142 |
|
sum(tensor, dim=None)
staticmethod
¶
sum along dim
Source code in oodeel/utils/tf_operator.py
224 225 226 227 |
|
t(tensor)
staticmethod
¶
Transpose function for tensor of rank 2
Source code in oodeel/utils/tf_operator.py
166 167 168 169 |
|
tril(tensor, diagonal=0)
staticmethod
¶
Set the upper triangle of the matrix formed by the last two dimensions of
Source code in oodeel/utils/tf_operator.py
218 219 220 221 222 |
|
unsqueeze(tensor, dim)
staticmethod
¶
expand_dim along dim
Source code in oodeel/utils/tf_operator.py
229 230 231 232 |
|
where(condition, input, other)
staticmethod
¶
Applies where function to condition
Source code in oodeel/utils/tf_operator.py
239 240 241 242 243 244 245 246 |
|
sanitize_input(tensor_arg_func)
¶
ensures the decorated function receives a tf.Tensor
Source code in oodeel/utils/tf_operator.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|