Commit 3004d8b3 authored by 吴升宇's avatar 吴升宇

add celery

parent 2d99094f
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import cv2 import cv2
import torch import torch
import skin_detector from skin_detector import skin_to_white
from torchvision import transforms as T from torchvision import transforms as T
...@@ -292,6 +292,7 @@ class COCODemo(object): ...@@ -292,6 +292,7 @@ class COCODemo(object):
colors = self.compute_colors_for_labels(labels).tolist() colors = self.compute_colors_for_labels(labels).tolist()
img = None
for mask, color in zip(masks, colors): for mask, color in zip(masks, colors):
thresh = mask[0, :, :, None] thresh = mask[0, :, :, None]
contours, hierarchy = cv2_util.findContours( contours, hierarchy = cv2_util.findContours(
...@@ -300,6 +301,9 @@ class COCODemo(object): ...@@ -300,6 +301,9 @@ class COCODemo(object):
color = [0, 0, 0] color = [0, 0, 0]
img = cv2.drawContours(image, contours, -1, color, 3) img = cv2.drawContours(image, contours, -1, color, 3)
if img is None:
return
# 把轮廓之外的颜色变为黑色 # 把轮廓之外的颜色变为黑色
a, b, c = img.shape a, b, c = img.shape
for x in range(a): for x in range(a):
...@@ -314,7 +318,7 @@ class COCODemo(object): ...@@ -314,7 +318,7 @@ class COCODemo(object):
img[x, y] = [0, 0, 0] img[x, y] = [0, 0, 0]
# 把图片皮肤颜色变为白色 # 把图片皮肤颜色变为白色
img = skin_detector(img) img = skin_to_white(img)
composite = img composite = img
return composite return composite
......
import os import os
from multiprocessing import Process
from threading import Thread
from webcam import img_to_three_color_map from webcam import img_to_three_color_map
def main(): def main():
rs = os.walk('../../fashionbase/images/dataset_0520/weiyi')
os.walk('../../fashionbase/images/dataset_0520/weiyi') for a, b, c in rs:
img_to_three_color_map(source_image, target_image) for i in c[:100]:
source_path = '../../fashionbase/images/dataset_0520/weiyi/' + i
target_path = 'output/' + i
print(source_path)
print(target_path)
img_to_three_color_map(source_path, target_path)
#p = Process(target=img_to_three_color_map, args=[source_path, target_path])
#p.start()
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -64,6 +64,7 @@ def img_to_three_color_map(source_path, target_path): ...@@ -64,6 +64,7 @@ def img_to_three_color_map(source_path, target_path):
img = cv2.imread(source_path) img = cv2.imread(source_path)
composite = coco_demo.run_on_opencv_image(img) composite = coco_demo.run_on_opencv_image(img)
if composite is not None:
cv2.imwrite(target_path, composite) cv2.imwrite(target_path, composite)
# cam = cv2.VideoCapture(0) # cam = cv2.VideoCapture(0)
# while True: # while True:
......
import os
from proj.tasks import img_reproce
def write_redis(source_path, target_path):
i = 0
while i < 3:
try:
r = img_reproce.apply_async(args=[source_path, target_path])
return r
except:
i += 1
def main():
rs = os.walk('../../fashionbase/images/dataset_0520/weiyi')
for a, b, files in rs:
for file in files:
source_path = '../../fashionbase/images/dataset_0520/weiyi/' + file
target_path = source_path.replace('dataset_0520', 'dataset_0520_10000')
print(source_path)
print(target_path)
# write_redis(source_path, target_path)
if __name__ == '__main__':
main()
from __future__ import absolute_import
from celery import Celery
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
app = Celery('proj', include=['proj.tasks'])
app.config_from_object('proj.config')
if __name__ == '__main__':
app.start()
BROKER_URL = 'redis://:zi1jlhVHtH8MGNqB@172.17.40.166:6379/3'
BROKER_TRANSPORT_OPTIONS = {'visibility_timeout': 86400} # 24 hour.
CELERY_RESULT_BACKEND = 'redis://:zi1jlhVHtH8MGNqB@172.17.40.166:6379/3' # 把任务结果存在了Redis
CELERY_TASK_SERIALIZER = 'msgpack' # 任务序列化和反序列化使用msgpack方案
CELERY_RESULT_SERIALIZER = 'json' # 读取任务结果一般性能要求不高,所以使用了可读性更好的JSON
CELERY_TASK_RESULT_EXPIRES = 60 * 60 * 24 # 任务过期时间,不建议直接写86400,应该让这样的magic数字表述更明显
CELERY_ACCEPT_CONTENT = ['json', 'msgpack'] # 指定接受的内容类型
\ No newline at end of file
from __future__ import absolute_import
from proj.celery import app
from demo.webcam import img_to_three_color_map
@app.task
def img_reproce(source_path, target_path):
img_to_three_color_map(source_path, target_path)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment