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.

track.py 2.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. """
  2. /**
  3. * Copyright 2020 Zhejiang Lab. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. * =============================================================
  17. */
  18. """
  19. # -*- coding: utf-8 -*-
  20. import sched
  21. import common.config as config
  22. import luascript.delaytaskscript as delay_script
  23. from track_only.hog_track import *
  24. schedule = sched.scheduler(time.time, time.sleep)
  25. delayId = ""
  26. def trackProcess(task, key):
  27. """Track task method.
  28. Args:
  29. task: dataset id.
  30. key: video file path.
  31. Returns:
  32. True: track success
  33. False: track failed
  34. """
  35. global delayId
  36. delayId = "\"" + eval(str(key, encoding="utf-8")) + "\""
  37. task = json.loads(task.decode('utf-8'))
  38. image_list = []
  39. label_list = []
  40. images_data = task['images']
  41. path = task['path']
  42. for file in images_data:
  43. filePath = path + "/origin/" + file
  44. annotationPath = path + "/annotation/" + file.split('.')[0]
  45. if not os.path.exists(filePath):
  46. continue
  47. if not os.path.exists(annotationPath):
  48. continue
  49. image_list.append(filePath)
  50. label_list.append(annotationPath)
  51. image_num = len(label_list)
  52. track_det = Detector(
  53. 'xxx.avi',
  54. min_confidence=0.35,
  55. max_cosine_distance=0.2,
  56. max_iou_distance=0.7,
  57. max_age=30,
  58. out_dir='results/')
  59. track_det.write_img = False
  60. RET = track_det.run_track(image_list, label_list)
  61. if RET == 'OK':
  62. return True
  63. else:
  64. return False
  65. def delaySchduled(inc, redisClient):
  66. """Delay task method.
  67. Args:
  68. inc: scheduled task time.
  69. redisClient: redis client.
  70. """
  71. try:
  72. print("delay:" + datetime.now().strftime("B%Y-%m-%d %H:%M:%S"))
  73. redisClient.eval(delay_script.delayTaskLua, 1, config.trackStartQueue, delayId, int(time.time()))
  74. schedule.enter(inc, 0, delaySchduled, (inc, redisClient))
  75. except Exception as e:
  76. print("delay error" + e)
  77. def delayKeyThread(redisClient):
  78. """Delay task thread.
  79. Args:
  80. redisClient: redis client.
  81. """
  82. schedule.enter(0, 0, delaySchduled, (5, redisClient))
  83. schedule.run()

一站式算法开发平台、高性能分布式深度学习框架、先进算法模型库、视觉模型炼知平台、数据可视化分析平台等一系列平台及工具,在模型高效分布式训练、数据处理和可视分析、模型炼知和轻量化等技术上形成独特优势,目前已在产学研等各领域近千家单位及个人提供AI应用赋能

Contributors (1)