def _transform(in_image,loaded,m_path):
if m_path == 'none':
return in_image
if not loaded:
serializers.load_npz(m_path, model)
if RUN_ON_GPU:
cuda.get_device(0).use() #assuming only one core
model.to_gpu()
print "loaded"
xp = np if not RUN_ON_GPU else cuda.cupy
image = xp.asarray(in_image, dtype=xp.float32).transpose(2, 0, 1)
image = image.reshape((1,) + image.shape)
image -= 120
x = Variable(image)
y = model(x)
result = cuda.to_cpu(y.data)
result = result.transpose(0, 2, 3, 1)
result = result.reshape((result.shape[1:]))
result += 120
result = np.uint8(result)
return result
评论列表
文章目录