Skip to content

Commit 24b53cf

Browse files
justin1121jvmncs
authored andcommitted
Fix tf 1.14.0 problems (tf-encrypted#676)
* tf140 * bump tf * try this * fix comment * leave 1.12.0
1 parent 65e6e23 commit 24b53cf

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

Diff for: Makefile

+10-1
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,19 @@ $(LIBSODIUM_OUT):
308308
$(MAKE) -C $(LIBSODIUM_DIR)
309309
$(MAKE) -C $(LIBSODIUM_DIR) install
310310

311+
UNAME_S := $(shell uname -s)
312+
ifeq ($(UNAME_S),Linux)
313+
FINAL_TF_LFLAGS = $(TF_LFLAGS)
314+
endif
315+
ifeq ($(UNAME_S),Darwin)
316+
FINAL_TF_LFLAGS = $(word 1,$(TF_LFLAGS)) -ltensorflow_framework
317+
endif
318+
311319
$(SECURE_OUT_PRE)$(CURRENT_TF_VERSION).so: $(LIBSODIUM_OUT) $(SECURE_IN) $(SECURE_IN_H)
312320
mkdir -p $(PACKAGE_DIR)/secure_random
321+
313322
g++ -std=c++11 -shared $(SECURE_IN) -o $(SECURE_OUT_PRE)$(CURRENT_TF_VERSION).so \
314-
-fPIC $(TF_CFLAGS) $(TF_LFLAGS) -O2 -I$(SODIUM_INSTALL)/include -L$(SODIUM_INSTALL)/lib -lsodium
323+
-fPIC $(TF_CFLAGS) $(FINAL_TF_LFLAGS) -O2 -I$(SODIUM_INSTALL)/include -L$(SODIUM_INSTALL)/lib -lsodium
315324

316325
build: $(SECURE_OUT_PRE)$(CURRENT_TF_VERSION).so
317326

Diff for: operations/secure_random/generators.h

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "tensorflow/core/framework/op.h"
2-
#include "tensorflow/core/kernels/bounds_check.h"
32
#include "tensorflow/core/framework/shape_inference.h"
43
#include "tensorflow/core/framework/op_kernel.h"
54
#include "tensorflow/core/lib/random/random_distributions.h"

Diff for: requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ numpy==1.14.5
88
protobuf==3.6.1
99
pyasn1==0.4.2
1010
s3transfer==0.1.13
11-
tensorflow==1.13.1
11+
tensorflow==1.14.0
1212
termcolor==1.1.0
1313
sphinx-rtd-theme==0.4.2
1414
recommonmark==0.4.0

Diff for: tf_encrypted/convert/convert_test.py

+25-8
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,13 @@ def test_keras_dense_convert(self):
327327
protocol='Pond',
328328
)
329329

330-
def test_keras_batchnorm_convert(self):
331-
test_input = np.ones([1, 28, 28, 1])
332-
self._test_with_ndarray_input_fn('keras_batchnorm',
333-
test_input,
334-
protocol='Pond')
330+
# TODO(justin1121): This is a bug in tf 1.14.0. We can re-enable
331+
# with tf > 1.14.0.
332+
# def test_keras_batchnorm_convert(self):
333+
# test_input = np.ones([1, 28, 28, 1])
334+
# self._test_with_ndarray_input_fn('keras_batchnorm',
335+
# test_input,
336+
# protocol='Pond')
335337

336338
def test_keras_global_avgpool_convert(self):
337339
test_input = np.ones([1, 10, 10, 3])
@@ -714,13 +716,16 @@ def export_split(filename, input_shape):
714716
def split_edge_case_builder(input_shape,
715717
filters=2,
716718
kernel_size=3):
719+
init = tf.keras.initializers.RandomNormal(seed=1)
720+
717721
x = tf.keras.Input(shape=input_shape[1:])
718722
y1, y2 = tf.keras.layers.Lambda(
719723
lambda tensor: tf.split(tensor,
720724
num_or_size_splits=2,
721725
axis=-1))(x)
722726
y = tf.keras.layers.Conv2D(filters,
723727
kernel_size,
728+
kernel_initializer=init,
724729
use_bias=True,
725730
padding='same')(y2)
726731
y = tf.keras.layers.Concatenate(axis=-1)([y1, y])
@@ -867,12 +872,15 @@ def keras_multilayer_builder(input_shape,
867872
kernel_size=3,
868873
pool_size=2,
869874
units=2):
875+
init = tf.keras.initializers.RandomNormal(seed=1)
870876
x = tf.keras.Input(shape=input_shape[1:])
871-
y = tf.keras.layers.Conv2D(filters, kernel_size)(x)
877+
y = tf.keras.layers.Conv2D(filters, kernel_size,
878+
kernel_initializer=init)(x)
872879
y = tf.keras.layers.ReLU()(y)
873880
y = tf.keras.layers.MaxPooling2D(pool_size)(y)
874881
y = tf.keras.layers.Flatten()(y)
875-
y = tf.keras.layers.Dense(units)(y)
882+
y = tf.keras.layers.Dense(units,
883+
kernel_initializer=init)(y)
876884

877885
return tf.keras.Model(x, y)
878886

@@ -924,10 +932,13 @@ def _keras_conv2d_core(shape=None, data=None):
924932
if shape is None:
925933
shape = data.shape
926934

935+
init = tf.keras.initializers.RandomNormal(seed=1)
936+
927937
model = Sequential()
928938
c2d = Conv2D(2, (3, 3),
929939
data_format="channels_last",
930940
use_bias=False,
941+
kernel_initializer=init,
931942
input_shape=shape[1:])
932943
model.add(c2d)
933944

@@ -955,8 +966,11 @@ def _keras_depthwise_conv2d_core(shape=None, data=None):
955966
if shape is None:
956967
shape = data.shape
957968

969+
init = tf.keras.initializers.RandomNormal(seed=1)
970+
958971
model = Sequential()
959972
c2d = DepthwiseConv2D((3, 3),
973+
depthwise_initializer=init,
960974
data_format="channels_last",
961975
use_bias=False,
962976
input_shape=shape[1:])
@@ -986,8 +1000,11 @@ def _keras_dense_core(shape=None, data=None):
9861000
if shape is None:
9871001
shape = data.shape
9881002

1003+
init = tf.keras.initializers.RandomNormal(seed=1)
1004+
9891005
model = Sequential()
9901006
d = Dense(2,
1007+
kernel_initializer=init,
9911008
use_bias=True,
9921009
input_shape=shape[1:])
9931010
model.add(d)
@@ -1001,7 +1018,7 @@ def export_keras_batchnorm(filename, input_shape):
10011018
model, _ = _keras_batchnorm_core(shape=input_shape)
10021019

10031020
sess = K.get_session()
1004-
output = model.get_layer('batch_normalization_v1').output
1021+
output = model.get_layer('batch_normalization').output
10051022
return export(output, filename, sess=sess)
10061023

10071024

0 commit comments

Comments
 (0)