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.

algorithm-ofrecord.py 3.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 os
  21. import json
  22. import threading
  23. import time
  24. import sys
  25. sys.path.append("../")
  26. import common.RedisUtil as f
  27. import common.config as config
  28. import luascript.starttaskscript as start_script
  29. import logging
  30. import traceback
  31. from entrance.executor import ofrecord
  32. logging.basicConfig(format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s',level=logging.DEBUG)
  33. basePath = '/nfs/'
  34. descPath = 'ofrecord/train'
  35. if __name__ == '__main__':
  36. """Ofrecord algorithm entry."""
  37. jsonData = config.loadJsonData(config.configPath)
  38. redisClient = f.getRedisConnection(jsonData["ip"], jsonData["port"], jsonData["database"], jsonData["password"])
  39. logging.info('init redis client %s', redisClient)
  40. t = threading.Thread(target=ofrecord.delayKeyThread, args=(redisClient,))
  41. t.setDaemon(True)
  42. t.start()
  43. while 1:
  44. try:
  45. if config.loadJsonData(config.sign) == 0:
  46. logging.info('not to execute new task')
  47. time.sleep(1)
  48. else:
  49. element = redisClient.eval(start_script.startTaskLua, 1, config.ofrecordTaskQueue,
  50. config.ofrecordStartQueue, int(time.time()))
  51. if len(element) > 0:
  52. key = element[0].decode()
  53. detail = f.getByKey(redisClient, key.replace('"', ''))
  54. jsonStr = json.loads(detail.decode())
  55. label_map = {}
  56. index = 0
  57. for item in jsonStr["datasetLabels"].keys():
  58. if index >= 0 and item != '@type':
  59. label_map[item] = jsonStr["datasetLabels"][item]
  60. index += 1
  61. ofrecord.execute(os.path.join(basePath, jsonStr["datasetPath"]),
  62. os.path.join(basePath, jsonStr["datasetPath"], descPath),
  63. label_map,
  64. jsonStr["files"],
  65. jsonStr["partNum"],
  66. element[0])
  67. logging.info('save result to redis')
  68. f.pushToQueue(redisClient, config.ofrecordFinishQueue, key)
  69. redisClient.zrem(config.ofrecordStartQueue, element[0])
  70. else:
  71. logging.info('task queue is empty.')
  72. time.sleep(2)
  73. except Exception as e:
  74. logging.error('except:', e)
  75. redisClient.zrem(config.ofrecordStartQueue, element[0])
  76. time.sleep(1)

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

Contributors (1)