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.

taskexecutor.py 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. """
  2. /**
  3. * Copyright 2020 Tianshu AI Platform. 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 codecs
  21. import os
  22. import sched
  23. import sys
  24. import json
  25. import logging
  26. import time
  27. import common.RedisUtil as f
  28. import common.config as config
  29. from entrance.executor import annotation as annotation
  30. from datetime import datetime
  31. import luascript.delaytaskscript as delay_script
  32. logging.basicConfig(format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s',
  33. level=logging.DEBUG)
  34. schedule = sched.scheduler(time.time, time.sleep)
  35. sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
  36. delayId = ""
  37. def annotationExecutor(redisClient, key):
  38. """Annotation task method.
  39. Args:
  40. redisClient: redis client.
  41. key: annotation task key.
  42. """
  43. global delayId
  44. print('-------------process one-----------------')
  45. try:
  46. delayId = "\"" + eval(str(key, encoding="utf-8")) + "\""
  47. logging.info('get element is {0}'.format(key))
  48. key = key.decode()
  49. jsonStr = f.getByKey(redisClient, key.replace('"', ''));
  50. print(jsonStr)
  51. jsonObject = json.loads(jsonStr.decode('utf-8'));
  52. image_path_list = []
  53. id_list = []
  54. annotation_url_list = []
  55. label_list = []
  56. label_list = jsonObject['labels']
  57. for fileObject in jsonObject['files']:
  58. pic_url = '/nfs/' + fileObject['url']
  59. image_path_list.append(pic_url)
  60. annotation_url = pic_url.replace("origin/", "annotation/")
  61. annotation_url_list.append(os.path.splitext(annotation_url)[0])
  62. isExists = os.path.exists(os.path.dirname(annotation_url))
  63. if not isExists:
  64. os.makedirs(os.path.dirname(annotation_url))
  65. id_list.append(fileObject['id'])
  66. print(image_path_list)
  67. print(annotation_url_list)
  68. print(label_list)
  69. coco_flag = 0
  70. if "labelType" in jsonObject:
  71. label_type = jsonObject['labelType']
  72. if label_type == 3:
  73. coco_flag = 80
  74. annotations = annotation._annotation(0, image_path_list, id_list, annotation_url_list, label_list, coco_flag);
  75. result = {"task": key, "annotations": annotations}
  76. f.pushToQueue(redisClient, config.annotationFinishQueue, json.dumps(result))
  77. redisClient.zrem(config.annotationStartQueue, key)
  78. except Exception as e:
  79. print(e)
  80. def delaySchduled(inc, redisClient):
  81. """Delay task method.
  82. Args:
  83. inc: scheduled task time.
  84. redisClient: redis client.
  85. """
  86. try:
  87. print("delay:" + datetime.now().strftime("B%Y-%m-%d %H:%M:%S"))
  88. redisClient.eval(delay_script.delayTaskLua, 1, config.annotationStartQueue, delayId, int(time.time()))
  89. schedule.enter(inc, 0, delaySchduled, (inc, redisClient))
  90. except Exception as e:
  91. print("delay error" + e)
  92. def delayKeyThread(redisClient):
  93. """Delay task thread.
  94. Args:
  95. redisClient: redis client.
  96. """
  97. schedule.enter(0, 0, delaySchduled, (5, redisClient))
  98. schedule.run()

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

Contributors (1)