{"cells":[{"metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","trusted":true},"cell_type":"code","source":"import cv2\nimport tensorflow as tf\n\ninput_image = tf.constant(cv2.imread('../input/landmark-retrieval-2020/train/0/0/0/0000059611c7d079.jpg'), dtype=tf.uint8)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"model = tf.saved_model.load(\"../input/google-2020-baseline/∩╗┐basline\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"class MyModel(tf.keras.Model):\n    def __init__(self):\n        super(MyModel, self).__init__()\n        self.model1 = model\n        self.f1 = self.model1.signatures[\"serving_default\"]\n        \n    @tf.function(input_signature=[\n      tf.TensorSpec(shape=[None, None, 3], dtype=tf.uint8, name='input_image')\n    ])\n    def call(self, input_image):\n        output_tensors = {}\n        \n        width = tf.cast(tf.shape(input_image)[0], dtype=tf.float32)\n        height = tf.cast(tf.shape(input_image)[1], dtype=tf.float32)\n        i1 = tf.cast(tf.image.resize(input_image, [tf.cast(pow(2,0.5) * width, dtype=tf.int32), tf.cast(pow(2,0.5) * height, dtype = tf.int32)]), dtype = input_image.dtype)\n        \n        output_tensors['global_descriptor'] = tf.identity(self.f1(i1)['global_descriptor'], name='global_descriptor')\n        return output_tensors","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"m = MyModel() #creating our model instance\n\nserved_function = m.call\ntf.saved_model.save(\n      m, export_dir=\"./my_model\", signatures={'serving_default': served_function})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!saved_model_cli show --dir \"../input/google-2020-baseline/∩╗┐basline\" --all","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!saved_model_cli show --dir ./my_model/ --all","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"imported3 = tf.saved_model.load(\"./my_model\")\nf3 = imported3.signatures[\"serving_default\"]\n\nf3(input_image)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"!ls ./my_model/variables","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"from zipfile import ZipFile\n\nwith ZipFile('submission.zip','w') as zip:           \n    zip.write('./my_model/saved_model.pb', arcname='saved_model.pb')\n    zip.write('./my_model/variables/variables.data-00000-of-00001', arcname='variables/variables.data-00000-of-00001') \n    zip.write('./my_model/variables/variables.index', arcname='variables/variables.index') ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}