Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files
demo.py
CHANGED
|
@@ -9,7 +9,7 @@ from PIL import Image
|
|
| 9 |
|
| 10 |
from matplotlib import pyplot as plt
|
| 11 |
|
| 12 |
-
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
|
| 13 |
|
| 14 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 15 |
|
|
|
|
| 9 |
|
| 10 |
from matplotlib import pyplot as plt
|
| 11 |
|
| 12 |
+
# os.environ['CUDA_VISIBLE_DEVICES'] = '0' # Removed for CPU compatibility
|
| 13 |
|
| 14 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 15 |
|
main.py
CHANGED
|
@@ -9,7 +9,7 @@ tf.disable_v2_behavior()
|
|
| 9 |
import imageio
|
| 10 |
from PIL import Image
|
| 11 |
|
| 12 |
-
os.environ['CUDA_VISIBLE_DEVICES'] = GPU_ID
|
| 13 |
|
| 14 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 15 |
|
|
|
|
| 9 |
import imageio
|
| 10 |
from PIL import Image
|
| 11 |
|
| 12 |
+
# os.environ['CUDA_VISIBLE_DEVICES'] = GPU_ID # Removed for CPU compatibility
|
| 13 |
|
| 14 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 15 |
|
net.py
CHANGED
|
@@ -86,8 +86,7 @@ class Network(object):
|
|
| 86 |
s = np.sqrt(1. /fan_in)
|
| 87 |
|
| 88 |
# create variable and specific GPU device
|
| 89 |
-
|
| 90 |
-
w = tf.get_variable(name, shape, dtype=self.dtype,
|
| 91 |
initializer=tf.random_uniform_initializer(minval=-s, maxval=s),
|
| 92 |
regularizer=regularizer, trainable=trainable)
|
| 93 |
|
|
@@ -96,8 +95,7 @@ class Network(object):
|
|
| 96 |
def _constant(self, shape, value=0, regularizer=None, trainable=None, name=None):
|
| 97 |
name = 'b' if name is None else name+'/b'
|
| 98 |
|
| 99 |
-
|
| 100 |
-
b = tf.get_variable(name, shape, dtype=self.dtype,
|
| 101 |
initializer=tf.constant_initializer(value=value),
|
| 102 |
regularizer=regularizer, trainable=trainable)
|
| 103 |
|
|
@@ -137,11 +135,10 @@ class Network(object):
|
|
| 137 |
x = (x - mean) / tf.sqrt(var + 1e-6)
|
| 138 |
|
| 139 |
# per channel gamma and beta
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
beta = tf.reshape(beta, [1, C, 1, 1])
|
| 145 |
|
| 146 |
tensor = tf.reshape(x, [-1, C, H, W]) * gamma + beta
|
| 147 |
# tranpose: [bs, c, h, w, c] to [bs, h, w, c] following the paper
|
|
@@ -197,18 +194,17 @@ class Network(object):
|
|
| 197 |
def _constant_kernel(self, shape, value=1.0, diag=False, flip=False, regularizer=None, trainable=None, name=None):
|
| 198 |
name = 'fixed_w' if name is None else name+'/fixed_w'
|
| 199 |
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
k = tf.get_variable(name, shape, dtype=self.dtype,
|
| 203 |
initializer=tf.constant_initializer(value=value),
|
| 204 |
regularizer=regularizer, trainable=trainable)
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
initializer=w,
|
| 213 |
regularizer=regularizer, trainable=trainable)
|
| 214 |
|
|
|
|
| 86 |
s = np.sqrt(1. /fan_in)
|
| 87 |
|
| 88 |
# create variable and specific GPU device
|
| 89 |
+
w = tf.get_variable(name, shape, dtype=self.dtype,
|
|
|
|
| 90 |
initializer=tf.random_uniform_initializer(minval=-s, maxval=s),
|
| 91 |
regularizer=regularizer, trainable=trainable)
|
| 92 |
|
|
|
|
| 95 |
def _constant(self, shape, value=0, regularizer=None, trainable=None, name=None):
|
| 96 |
name = 'b' if name is None else name+'/b'
|
| 97 |
|
| 98 |
+
b = tf.get_variable(name, shape, dtype=self.dtype,
|
|
|
|
| 99 |
initializer=tf.constant_initializer(value=value),
|
| 100 |
regularizer=regularizer, trainable=trainable)
|
| 101 |
|
|
|
|
| 135 |
x = (x - mean) / tf.sqrt(var + 1e-6)
|
| 136 |
|
| 137 |
# per channel gamma and beta
|
| 138 |
+
gamma = tf.get_variable(name+'/gamma', [C], dtype=self.dtype, initializer=tf.constant_initializer(1.0))
|
| 139 |
+
beta = tf.get_variable(name+'/beta', [C], dtype=self.dtype, initializer=tf.constant_initializer(0.0))
|
| 140 |
+
gamma = tf.reshape(gamma, [1, C, 1, 1])
|
| 141 |
+
beta = tf.reshape(beta, [1, C, 1, 1])
|
|
|
|
| 142 |
|
| 143 |
tensor = tf.reshape(x, [-1, C, H, W]) * gamma + beta
|
| 144 |
# tranpose: [bs, c, h, w, c] to [bs, h, w, c] following the paper
|
|
|
|
| 194 |
def _constant_kernel(self, shape, value=1.0, diag=False, flip=False, regularizer=None, trainable=None, name=None):
|
| 195 |
name = 'fixed_w' if name is None else name+'/fixed_w'
|
| 196 |
|
| 197 |
+
if not diag:
|
| 198 |
+
k = tf.get_variable(name, shape, dtype=self.dtype,
|
|
|
|
| 199 |
initializer=tf.constant_initializer(value=value),
|
| 200 |
regularizer=regularizer, trainable=trainable)
|
| 201 |
+
else:
|
| 202 |
+
w = tf.eye(shape[0], num_columns=shape[1])
|
| 203 |
+
if flip:
|
| 204 |
+
w = tf.reshape(w, (shape[0], shape[1], 1))
|
| 205 |
+
w = tf.image.flip_left_right(w)
|
| 206 |
+
w = tf.reshape(w, shape)
|
| 207 |
+
k = tf.get_variable(name, None, dtype=self.dtype, # constant initializer dont specific shape
|
| 208 |
initializer=w,
|
| 209 |
regularizer=regularizer, trainable=trainable)
|
| 210 |
|