nn_utils.py 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. #
  15. # author: Tomasz Grel ([email protected])
  16. from collections import OrderedDict
  17. def create_inputs_dict(numerical_features, categorical_features):
  18. # Passing inputs as (numerical_features, categorical_features) changes the model
  19. # input signature to (<tensor, [list of tensors]>).
  20. # This leads to errors while loading the saved model.
  21. # TF flattens the inputs while loading the model,
  22. # so the inputs are converted from (<tensor, [list of tensors]>) -> [list of tensors]
  23. # see _set_inputs function in training_v1.py:
  24. # https://github.com/tensorflow/tensorflow/blob/7628750678786f1b65e8905fb9406d8fbffef0db/tensorflow/python/keras/engine/training_v1.py#L2588)
  25. inputs = OrderedDict()
  26. inputs['numerical_features'] = numerical_features
  27. inputs['categorical_features'] = categorical_features
  28. return inputs