tf-encrypted / tf-encrypted

A Framework for Encrypted Machine Learning in TensorFlow

Home Page:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

got NotImplementedError: while trying to clone model

johantandy opened this issue · comments

Hi im trying to clone my existing pretrain weight with tfe.keras.models.clone_model(model1) but got error : NotImplementedError:

NotImplementedError                       Traceback (most recent call last)
<ipython-input-13-f292eb5a9067> in <module>
      1 tf.reset_default_graph()
      2 with tfe.protocol.SecureNN():
----> 3     tfe_model = tfe.keras.models.clone_model(model1)

~/anaconda3/envs/py37/lib/python3.7/site-packages/tf_encrypted/keras/models/ in clone_model(model)
    242   weights = model.get_weights()
--> 244   tfe_model = model_from_config(config)
    245   tfe_model.set_weights(weights)

~/anaconda3/envs/py37/lib/python3.7/site-packages/tf_encrypted/keras/models/ in model_from_config(config)
    224   for k_l_c in config['layers']:
    225     tfe_layer = _instantiate_tfe_layer(k_l_c)
--> 226     tfe_model.add(tfe_layer)
    228   return tfe_model

~/anaconda3/envs/py37/lib/python3.7/site-packages/tf_encrypted/keras/models/ in add(self, layer)
     56       x = Input(
     57           batch_shape=batch_shape,
---> 58  + '_input')
     59       # This will build the current layer
     60       # and create the node connecting the current layer

~/anaconda3/envs/py37/lib/python3.7/site-packages/tf_encrypted/keras/engine/ in Input(shape, batch_size, name, dtype, sparse, tensor, **kwargs)
    157         dtype=dtype,
    158         sparse=sparse,
--> 159         input_tensor=tensor)
    160   else:
    161     input_layer = InputLayer(

~/anaconda3/envs/py37/lib/python3.7/site-packages/tf_encrypted/keras/engine/ in __init__(self, input_shape, batch_size, dtype, input_tensor, sparse, name, **kwargs)
     50     if batch_size is None:
---> 51       raise NotImplementedError()
     52     if input_tensor is not None:
     53       raise NotImplementedError()


my model code :

import tensorflow as tf
from matplotlib import pyplot
from tensorflow.keras.utils import to_categorical
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D
from tensorflow.keras.layers import MaxPooling2D
from tensorflow.keras.layers import Dense
from tensorflow.keras.layers import Flatten
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from collections import OrderedDict
import tf_encrypted as tfe
import tf_encrypted.keras.backend as KE

def define_model():
	model = Sequential()
	model.add(Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_uniform', padding='same', input_shape=(200, 200, 3)))
	model.add(MaxPooling2D((2, 2)))
	model.add(Dense(128, activation='relu', kernel_initializer='he_uniform'))
	model.add(Dense(1, activation='sigmoid'))
	# compile model
	opt = SGD(lr=0.001, momentum=0.9)
	model.compile(optimizer=opt, loss='binary_crossentropy', metrics=['accuracy'])
	return model

model1 = define_model()

pre_trained_weights = 'cat-dogs-encrypted_image.h5'

with tfe.protocol.SecureNN():
    tfe_model = tfe.keras.models.clone_model(model1)

any idea what's wrong with the tf encrypted library or something wrong in my model code ?
thanks !!

This looks similar to #787, does the solution there fix your issue?

Closing this due to inactivity. Please open a new issue if this problem still exists in the most recent version 0.7.0.