@@ -32,7 +32,7 @@ def test_noise(self):
32
32
inputs = tf .placeholder (tf .float32 , (None , 1 ))
33
33
layer = entropy_models .EntropyBottleneck ()
34
34
noisy , _ = layer (inputs , training = True )
35
- with self .test_session () as sess :
35
+ with self .cached_session () as sess :
36
36
sess .run (tf .global_variables_initializer ())
37
37
values = np .linspace (- 50 , 50 , 100 )[:, None ]
38
38
noisy , = sess .run ([noisy ], {inputs : values })
@@ -45,7 +45,7 @@ def test_quantization_init(self):
45
45
inputs = tf .placeholder (tf .float32 , (None , 1 ))
46
46
layer = entropy_models .EntropyBottleneck ()
47
47
quantized , _ = layer (inputs , training = False )
48
- with self .test_session () as sess :
48
+ with self .cached_session () as sess :
49
49
sess .run (tf .global_variables_initializer ())
50
50
values = np .linspace (- 50 , 50 , 100 )[:, None ]
51
51
quantized , = sess .run ([quantized ], {inputs : values })
@@ -61,7 +61,7 @@ def test_quantization(self):
61
61
opt = tf .train .GradientDescentOptimizer (learning_rate = 1 )
62
62
self .assertEqual (1 , len (layer .losses ))
63
63
step = opt .minimize (layer .losses [0 ])
64
- with self .test_session () as sess :
64
+ with self .cached_session () as sess :
65
65
sess .run (tf .global_variables_initializer ())
66
66
sess .run (step )
67
67
values = np .linspace (- 50 , 50 , 100 )[:, None ]
@@ -79,7 +79,7 @@ def test_codec_init(self):
79
79
data_format = "channels_last" , init_scale = 30 )
80
80
bitstrings = layer .compress (inputs )
81
81
decoded = layer .decompress (bitstrings , tf .shape (inputs )[1 :])
82
- with self .test_session () as sess :
82
+ with self .cached_session () as sess :
83
83
sess .run (tf .global_variables_initializer ())
84
84
values = np .linspace (- 50 , 50 , 100 )[None , :, None ]
85
85
decoded , = sess .run ([decoded ], {inputs : values })
@@ -98,7 +98,7 @@ def test_codec(self):
98
98
opt = tf .train .GradientDescentOptimizer (learning_rate = 1 )
99
99
self .assertEqual (1 , len (layer .losses ))
100
100
step = opt .minimize (layer .losses [0 ])
101
- with self .test_session () as sess :
101
+ with self .cached_session () as sess :
102
102
sess .run (tf .global_variables_initializer ())
103
103
sess .run (step )
104
104
self .assertEqual (1 , len (layer .updates ))
@@ -120,7 +120,7 @@ def test_channels_last(self):
120
120
quantized , _ = layer (inputs , training = False )
121
121
bitstrings = layer .compress (inputs )
122
122
decoded = layer .decompress (bitstrings , tf .shape (inputs )[1 :])
123
- with self .test_session () as sess :
123
+ with self .cached_session () as sess :
124
124
sess .run (tf .global_variables_initializer ())
125
125
self .assertEqual (1 , len (layer .updates ))
126
126
sess .run (layer .updates [0 ])
@@ -141,7 +141,7 @@ def test_channels_first(self):
141
141
quantized , _ = layer (inputs , training = False )
142
142
bitstrings = layer .compress (inputs )
143
143
decoded = layer .decompress (bitstrings , tf .shape (inputs )[1 :])
144
- with self .test_session () as sess :
144
+ with self .cached_session () as sess :
145
145
sess .run (tf .global_variables_initializer ())
146
146
self .assertEqual (1 , len (layer .updates ))
147
147
sess .run (layer .updates [0 ])
@@ -161,7 +161,7 @@ def test_compress(self):
161
161
data_format = "channels_first" , filters = (), init_scale = 2 )
162
162
bitstrings = layer .compress (inputs )
163
163
decoded = layer .decompress (bitstrings , tf .shape (inputs )[1 :])
164
- with self .test_session () as sess :
164
+ with self .cached_session () as sess :
165
165
values = 8 * np .random .uniform (size = (2 , 3 , 9 )) - 4
166
166
sess .run (tf .global_variables_initializer ())
167
167
self .assertEqual (1 , len (layer .updates ))
@@ -213,7 +213,7 @@ def test_decompress(self):
213
213
layer ._quantized_cdf = quantized_cdf
214
214
layer ._cdf_length = cdf_length
215
215
decoded = layer .decompress (bitstrings , input_shape [1 :])
216
- with self .test_session () as sess :
216
+ with self .cached_session () as sess :
217
217
sess .run (tf .global_variables_initializer ())
218
218
decoded , = sess .run ([decoded ], {
219
219
bitstrings : self .bitstrings , input_shape : self .expected .shape ,
@@ -233,7 +233,7 @@ def test_normalization(self):
233
233
inputs = tf .placeholder (tf .float32 , (None , 1 ))
234
234
layer = entropy_models .EntropyBottleneck (filters = (2 ,))
235
235
_ , likelihood = layer (inputs , training = True )
236
- with self .test_session () as sess :
236
+ with self .cached_session () as sess :
237
237
sess .run (tf .global_variables_initializer ())
238
238
x = np .repeat (np .arange (- 200 , 201 ), 2000 )[:, None ]
239
239
likelihood , = sess .run ([likelihood ], {inputs : x })
@@ -251,7 +251,7 @@ def test_entropy_estimates(self):
251
251
_ , likelihood = layer (inputs , training = False )
252
252
disc_entropy = tf .reduce_sum (tf .log (likelihood )) / - np .log (2 )
253
253
bitstrings = layer .compress (inputs )
254
- with self .test_session () as sess :
254
+ with self .cached_session () as sess :
255
255
sess .run (tf .global_variables_initializer ())
256
256
self .assertEqual (1 , len (layer .updates ))
257
257
sess .run (layer .updates [0 ])
@@ -272,7 +272,7 @@ def test_noise(self):
272
272
scale = tf .placeholder (tf .float32 , [None ])
273
273
layer = self .subclass (scale , [1 ])
274
274
noisy , _ = layer (inputs , training = True )
275
- with self .test_session () as sess :
275
+ with self .cached_session () as sess :
276
276
sess .run (tf .global_variables_initializer ())
277
277
values = np .linspace (- 50 , 50 , 100 )
278
278
noisy , = sess .run ([noisy ], {
@@ -288,7 +288,7 @@ def test_quantization(self):
288
288
scale = tf .placeholder (tf .float32 , [None ])
289
289
layer = self .subclass (scale , [1 ], mean = None )
290
290
quantized , _ = layer (inputs , training = False )
291
- with self .test_session () as sess :
291
+ with self .cached_session () as sess :
292
292
sess .run (tf .global_variables_initializer ())
293
293
values = np .linspace (- 50 , 50 , 100 )
294
294
quantized , = sess .run ([quantized ], {
@@ -305,7 +305,7 @@ def test_quantization_mean(self):
305
305
mean = tf .placeholder (tf .float32 , [None ])
306
306
layer = self .subclass (scale , [1 ], mean = mean )
307
307
quantized , _ = layer (inputs , training = False )
308
- with self .test_session () as sess :
308
+ with self .cached_session () as sess :
309
309
sess .run (tf .global_variables_initializer ())
310
310
values = np .linspace (- 50 , 50 , 100 )
311
311
mean_values = np .random .normal (size = values .shape )
@@ -327,7 +327,7 @@ def test_codec(self):
327
327
scale , [2 ** x for x in range (- 10 , 10 )], mean = None )
328
328
bitstrings = layer .compress (inputs )
329
329
decoded = layer .decompress (bitstrings )
330
- with self .test_session () as sess :
330
+ with self .cached_session () as sess :
331
331
sess .run (tf .global_variables_initializer ())
332
332
values = np .linspace (- 50 , 50 , 100 )[None ]
333
333
decoded , = sess .run ([decoded ], {
@@ -346,7 +346,7 @@ def test_codec_mean(self):
346
346
scale , [2 ** x for x in range (- 10 , 10 )], mean = mean )
347
347
bitstrings = layer .compress (inputs )
348
348
decoded = layer .decompress (bitstrings )
349
- with self .test_session () as sess :
349
+ with self .cached_session () as sess :
350
350
sess .run (tf .global_variables_initializer ())
351
351
values = np .linspace (- 50 , 50 , 100 )[None ]
352
352
mean_values = np .random .normal (size = values .shape )
@@ -369,7 +369,7 @@ def test_multiple_dimensions(self):
369
369
quantized , _ = layer (inputs , training = False )
370
370
bitstrings = layer .compress (inputs )
371
371
decoded = layer .decompress (bitstrings )
372
- with self .test_session () as sess :
372
+ with self .cached_session () as sess :
373
373
sess .run (tf .global_variables_initializer ())
374
374
values = 10 * np .random .normal (size = (2 , 5 , 3 , 7 ))
375
375
noisy , quantized , decoded = sess .run (
@@ -391,7 +391,7 @@ def test_compress(self):
391
391
layer = self .subclass (scale , scale_table , indexes = indexes )
392
392
bitstrings = layer .compress (inputs )
393
393
decoded = layer .decompress (bitstrings )
394
- with self .test_session () as sess :
394
+ with self .cached_session () as sess :
395
395
values = 8 * np .random .uniform (size = shape ) - 4
396
396
indexes = np .random .randint (
397
397
0 , len (scale_table ), size = shape , dtype = np .int32 )
@@ -415,7 +415,7 @@ def test_decompress(self):
415
415
layer = self .subclass (
416
416
scale , scale_table , indexes = indexes , dtype = tf .float32 )
417
417
decoded = layer .decompress (bitstrings )
418
- with self .test_session () as sess :
418
+ with self .cached_session () as sess :
419
419
sess .run (tf .global_variables_initializer ())
420
420
decoded , = sess .run ([decoded ], {
421
421
bitstrings : self .bitstrings ,
@@ -437,7 +437,7 @@ def test_quantile_function(self):
437
437
# Test that quantile function inverts cumulative.
438
438
scale = tf .placeholder (tf .float64 , [None ])
439
439
layer = self .subclass (scale , [1 ], dtype = tf .float64 )
440
- with self .test_session () as sess :
440
+ with self .cached_session () as sess :
441
441
sess .run (tf .global_variables_initializer ())
442
442
quantiles = np .array ([1e-5 , 1e-2 , .1 , .5 , .6 , .8 ])
443
443
locations = layer ._standardized_quantile (quantiles )
@@ -452,7 +452,7 @@ def test_distribution(self):
452
452
scale = tf .placeholder (tf .float32 , [None , None ])
453
453
layer = self .subclass (scale , [1 ], scale_bound = 0 , mean = None )
454
454
_ , likelihood = layer (inputs , training = False )
455
- with self .test_session () as sess :
455
+ with self .cached_session () as sess :
456
456
sess .run (tf .global_variables_initializer ())
457
457
values = np .arange (- 5 , 1 )[:, None ] # must be integers due to quantization
458
458
scales = 2 ** np .linspace (- 3 , 3 , 10 )[None , :]
@@ -476,7 +476,7 @@ def test_entropy_estimates(self):
476
476
disc_entropy = tf .reduce_mean (tf .log (likelihood ), axis = 1 )
477
477
disc_entropy /= - np .log (2 )
478
478
bitstrings = layer .compress (inputs )
479
- with self .test_session () as sess :
479
+ with self .cached_session () as sess :
480
480
sess .run (tf .global_variables_initializer ())
481
481
scales = np .repeat ([layer .scale_table ], 10000 , axis = 0 ).T
482
482
values = self .scipy_class .rvs (scale = scales , size = scales .shape )
0 commit comments