@@ -0,0 +1,2024 @@
+#!/usr/bin/env python%0A# Copyright 2017 Calico LLC%0A#%0A# Licensed under the Apache License, Version 2.0 (the %22License%22);%0A# you may not use this file except in compliance with the License.%0A# You may obtain a copy of the License at%0A#%0A#     https://www.apache.org/licenses/LICENSE-2.0%0A#%0A# Unless required by applicable law or agreed to in writing, software%0A# distributed under the License is distributed on an %22AS IS%22 BASIS,%0A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A# See the License for the specific language governing permissions and%0A# limitations under the License.%0A# =========================================================================%0A%0Afrom __future__ import print_function%0Afrom optparse import OptionParser%0Aimport os%0A%0Aimport json%0Aimport tensorflow as tf%0Aif tf.__version__%5B0%5D == '1':%0A  tf.compat.v1.enable_eager_execution()%0A%0Afrom basenji import seqnn%0A%0A%22%22%22%0Asave_trunk.py%0A%0ARestore a model, and then save the trunk only.%0A%22%22%22%0A%0A################################################################################%0A# main%0A################################################################################%0Adef main():%0A  usage = 'usage: %25prog %5Boptions%5D %3Cparams_file%3E %3Cin_model_file%3E %3Cout_model_file%3E'%0A  parser = OptionParser(usage)%0A  (options, args) = parser.parse_args()%0A%0A  if len(args) != 3:%0A    parser.error('Must provide parameters, input model, and output model')%0A  else:%0A    params_file = args%5B0%5D%0A    in_model_file = args%5B1%5D%0A    out_model_file = args%5B2%5D%0A%0A  # read model parameters%0A  with open(params_file) as params_open:%0A    params = json.load(params_open)%0A  params_model = params%5B'model'%5D%0A  params_train = params%5B'train'%5D%0A%0A  # restore model%0A  seqnn_model = seqnn.SeqNN(params_model)%0A  seqnn_model.restore(in_model_file)%0A%0A  # save trunk%0A  seqnn_model.save(out_model_file, trunk=True)%0A%0A################################################################################%0A# __main__%0A################################################################################%0Aif __name__ == '__main__':%0A  main()%0A

save model trunk