You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

train.py 4.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright 2021 The KubeEdge Authors.
  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. import logging
  15. import tensorflow as tf
  16. import sedna
  17. from interface import Interface
  18. from sedna.incremental_learning import IncrementalConfig
  19. LOG = logging.getLogger(__name__)
  20. MODEL_URL = IncrementalConfig().model_url
  21. def main():
  22. tf.set_random_seed(22)
  23. class_names = sedna.context.get_parameters("class_names")
  24. # load dataset.
  25. train_data = sedna.load_train_dataset(data_format='txt')
  26. # read parameters from deployment config.
  27. obj_threshold = sedna.context.get_parameters("obj_threshold")
  28. nms_threshold = sedna.context.get_parameters("nms_threshold")
  29. input_shape = sedna.context.get_parameters("input_shape")
  30. epochs = sedna.context.get_parameters('epochs')
  31. batch_size = sedna.context.get_parameters('batch_size')
  32. tf.flags.DEFINE_string('train_url', default=MODEL_URL,
  33. help='train url for model')
  34. tf.flags.DEFINE_string('log_url', default=None, help='log url for model')
  35. tf.flags.DEFINE_string('checkpoint_url', default=None,
  36. help='checkpoint url for model')
  37. tf.flags.DEFINE_string('model_name', default=None,
  38. help='url for train annotation files')
  39. tf.flags.DEFINE_list('class_names', default=class_names.split(','),
  40. # 'helmet,helmet-on,person,helmet-off'
  41. help='label names for the training datasets')
  42. tf.flags.DEFINE_list('input_shape',
  43. default=[int(x) for x in input_shape.split(',')],
  44. help='input_shape') # [352, 640]
  45. tf.flags.DEFINE_integer('max_epochs', default=epochs,
  46. help='training number of epochs')
  47. tf.flags.DEFINE_integer('batch_size', default=batch_size,
  48. help='training batch size')
  49. tf.flags.DEFINE_boolean('load_imagenet_weights', default=False,
  50. help='if load imagenet weights or not')
  51. tf.flags.DEFINE_string('inference_device',
  52. default='GPU',
  53. help='which type of device is used to do inference,'
  54. ' only CPU, GPU or 310D')
  55. tf.flags.DEFINE_boolean('copy_to_local', default=True,
  56. help='if load imagenet weights or not')
  57. tf.flags.DEFINE_integer('num_gpus', default=1, help='use number of gpus')
  58. tf.flags.DEFINE_boolean('finetuning', default=False,
  59. help='use number of gpus')
  60. tf.flags.DEFINE_boolean('label_changed', default=False,
  61. help='whether number of labels is changed or not')
  62. tf.flags.DEFINE_string('learning_rate', default='0.001',
  63. help='label names for the training datasets')
  64. tf.flags.DEFINE_string('obj_threshold', default=obj_threshold,
  65. help='label names for the training datasets')
  66. tf.flags.DEFINE_string('nms_threshold', default=nms_threshold,
  67. help='label names for the training datasets')
  68. tf.flags.DEFINE_string('net_type', default='resnet18',
  69. help='resnet18 or resnet18_nas')
  70. tf.flags.DEFINE_string('nas_sequence', default='64_1-2111-2-1112',
  71. help='resnet18 or resnet18_nas')
  72. tf.flags.DEFINE_string('deploy_model_format', default=None,
  73. help='the format for the converted model')
  74. tf.flags.DEFINE_string('result_url', default=None,
  75. help='result url for training')
  76. model = Interface()
  77. sedna.incremental_learning.train(model=model,
  78. train_data=train_data,
  79. epochs=epochs,
  80. batch_size=batch_size,
  81. class_names=class_names,
  82. input_shape=input_shape,
  83. obj_threshold=obj_threshold,
  84. nms_threshold=nms_threshold)
  85. if __name__ == '__main__':
  86. main()