-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path_tensorflow.py
49 lines (36 loc) · 1.04 KB
/
_tensorflow.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
tensorflow backend
"""
try:
import tensorflow as tf
except ImportError:
tf = None
from ._backend import Backend, assert_backend_available
class TensorflowBackend(Backend):
def __str__(self):
return "tensorflow"
def is_available(self):
return tf is not None
@assert_backend_available
def is_compatible(self, args):
if list(filter(lambda t: isinstance(args, t), [
tf.Tensor,
tf.Variable
])) != []:
return True
# "tensorflow backend requires input to be an isinstance of `tensorflow.Tensor` or `tensorflow.Variable`"
return False
def concatenate(self, tensor, axis):
return tf.concat(tensor, axis = axis)
def ones_like(self, tensor):
return tf.ones_like(tensor)
def multiply(self, x, y):
return tf.multiply(x, y)
def expand_dims(self, tensor, axis):
return tf.expand_dims(tensor, axis)
def get_dims(self, tensor):
return [dim.value for dim in tensor.get_shape()]
def reshape(self, tensor, shape):
return tf.reshape(tensor, shape)
def matmul(self, tensor1, tensor2):
return tf.matmul(tensor1, tensor2)