Skip to content

Commit eea9d76

Browse files
authored
Use feature detection instead of version detection
Python porting best practice [___use feature detection instead of version detection___](https://docs.python.org/3/howto/pyporting.html#use-feature-detection-instead-of-version-detection).
1 parent 66d173e commit eea9d76

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

deepctr/layers/activation.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
77
"""
88

9-
import sys
10-
119
import tensorflow as tf
1210
from tensorflow.python.keras.initializers import Zeros
1311
from tensorflow.python.keras.layers import Layer
1412

13+
try:
14+
unicode
15+
except NameError:
16+
unicode = str
17+
1518

1619
class Dice(Layer):
1720
"""The Data Adaptive Activation Function in DIN,which can be viewed as a generalization of PReLu and can adaptively adjust the rectified point according to distribution of input data.
@@ -61,9 +64,9 @@ def get_config(self, ):
6164

6265

6366
def activation_layer(activation):
64-
if activation == "dice" or activation == "Dice":
67+
if activation in ("dice", "Dice"):
6568
act_layer = Dice()
66-
elif (isinstance(activation, str)) or (sys.version_info.major == 2 and isinstance(activation, (str, unicode))):
69+
elif isinstance(activation, (str, unicode)):
6770
act_layer = tf.keras.layers.Activation(activation)
6871
elif issubclass(activation, Layer):
6972
act_layer = activation()

0 commit comments

Comments
 (0)