【发布时间】:2017-12-14 12:20:30
【问题描述】:
我们正在构建一个用于人脸识别的脚本,主要使用 tensorflow 来实现基本的识别功能,来自视频。
当我们直接使用python test-reco.py(以视频路径作为参数)尝试软时,它可以完美运行。
现在我们正试图通过我们的网站将它整合到一个 celery 任务中。
这里是主要代码:
def extract_labels(self, path_to_video):
if not os.path.exists(path_to_video):
print("NO VIDEO!")
return None
video = VideoFileClip(path_to_video)
n_frames = int(video.fps * video.duration)
out = []
for i, frame in enumerate(video.iter_frames()):
if self.verbose > 0:
print(
'processing frame:',
str(i).zfill(len(str(n_frames))),
'/',
n_frames
)
try:
rect = face_detector(frame[::2, ::2], 0)[0]
y0, x0, y1, x1 = np.array([rect.left(), rect.top(), rect.right(), rect.bottom()])*2
bbox = frame[x0:x1, y0:y1]
bbox = resize(bbox, [128, 128])
bbox = rgb2gray(bbox)
bbox = equalize_hist(bbox)
y_hat = self.model.predict(bbox[None, :, :, None], verbose=1, batch_size=1)[0]
# y_hat = np.ones(7)
out.append(y_hat)
except IndexError as e:
print(out)
print(e)
我们需要尝试捕捉,因为有时第一帧中没有任何人脸。
但是我们有这一行:
y_hat = self.model.predict(bbox[None, :, :, None], verbose=1, batch_size=1)[0]
阻塞。就像一个无限循环。
bbox 不为空。
celery worker 只是阻塞它并且你不能退出进程(暖/冷退出永远不会发生)
Celery 的 tensorflow 有什么特定的关系吗?
【问题讨论】:
-
这一行
self.model.predict在没有你的芹菜任务的情况下返回与否? -
所以我们尝试了录制的视频和本地视频(当我们手动执行脚本时本地视频工作),但是如果我直接通过视图执行脚本,
out为空(应该用out.append(y_hat)填充),从 try/catch 打印的唯一错误是:Tensor Tensor("dense_1/Softmax:0", shape=(?, 7), dtype=float32) is not an element of this graph. -
我们已经打印了这个:
print("IN BOX", bbox[None, :, :, None]),它有正确的值:(1, 128, 128, 1)所以我很困惑..
标签: django tensorflow celery keras