mirror of
https://github.com/wassname/keras-contrib.git
synced 2026-06-27 16:10:11 +08:00
fixed python 2 bug with divison
StringIO depends now on python 2/3 as it should PEP8 fixes
This commit is contained in:
@@ -78,7 +78,7 @@ class DeadReluDetector(Callback):
|
||||
|
||||
dead_neurons = np.sum(np.sum(activation_values, axis=axis) == 0)
|
||||
|
||||
dead_neurons_share = dead_neurons / total_featuremaps
|
||||
dead_neurons_share = float(dead_neurons) / float(total_featuremaps)
|
||||
if (self.verbose and dead_neurons > 0) or dead_neurons_share >= self.dead_neurons_share_threshold:
|
||||
str_warning = 'Layer {} (#{}) has {} dead neurons ({:.2%})!'.format(layer_name, layer_index,
|
||||
dead_neurons, dead_neurons_share)
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import pytest
|
||||
import numpy as np
|
||||
import sys
|
||||
import io
|
||||
|
||||
if (sys.version_info > (3, 0)):
|
||||
from io import StringIO
|
||||
else:
|
||||
from StringIO import StringIO
|
||||
|
||||
from keras_contrib import callbacks
|
||||
from keras.models import Sequential
|
||||
@@ -17,8 +21,10 @@ def check_print(do_train, expected_warnings, nr_dead=None, perc_dead=None):
|
||||
:param nr_dead: int
|
||||
:param perc_dead: float, 10% should be written as 0.1
|
||||
"""
|
||||
|
||||
saved_stdout = sys.stdout
|
||||
out = io.StringIO()
|
||||
|
||||
out = StringIO()
|
||||
sys.stdout = out # overwrite current stdout
|
||||
|
||||
do_train()
|
||||
@@ -133,7 +139,7 @@ def test_DeadDeadReluDetector_conv():
|
||||
shape_weights = (5, 5, 4, n_out)
|
||||
shape_out = (n_samples, n_out)
|
||||
|
||||
def do_test(weights_bias, expected_warnings, verbose, nr_dead = None, perc_dead = None):
|
||||
def do_test(weights_bias, expected_warnings, verbose, nr_dead=None, perc_dead=None):
|
||||
"""
|
||||
:param perc_dead: as float, 10% should be written as 0.1
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user