未验证 提交 9c673e6b 编写于 作者: L lijianshe02 提交者: GitHub

refine duplicate frames and fix some bugs (#81)

* refine duplicate frames and fix some bugs
上级 358279b7
......@@ -33,8 +33,8 @@ python tools/psgan_infer.py \
2. Downloading the landmarks [data](https://paddlegan.bj.bcebos.com/landmarks.tar), and uncompress it
3. Runnint the following command to substitute files:
```
mv landmarks/makeup MT-Dataset/landmarks/makeup
mv landmarks/non-makeup MT-Dataset/landmarks/non-makeup
rm -rf MT-Dataset/landmarks/makeup && mv landmarks/makeup MT-Dataset/landmarks/
rm -rf MT-Dataset/landmarks/non-makeup && mv landmarks/non-makeup MT-Dataset/landmarks/
cp landmarks/train_makeup.txt MT-Dataset/train_makeup.txt
cp landmarks/train_non-makeup.txt MT-Dataset/train_non-makeup.txt
```
......
......@@ -33,8 +33,8 @@ python tools/psgan_infer.py \
2. 下载landmarks数据[lmks](https://paddlegan.bj.bcebos.com/landmarks.tar),并解压
3. 运行如下命令进行文件夹及文件替换:
```
mv landmarks/makeup MT-Dataset/landmarks/makeup
mv landmarks/non-makeup MT-Dataset/landmarks/non-makeup
rm -rf MT-Dataset/landmarks/makeup && mv landmarks/makeup MT-Dataset/landmarks/
rm -rf MT-Dataset/landmarks/non-makeup && mv landmarks/non-makeup MT-Dataset/landmarks/
cp landmarks/train_makeup.txt MT-Dataset/train_makeup.txt
cp landmarks/train_non-makeup.txt MT-Dataset/train_non-makeup.txt
```
......
......@@ -269,6 +269,7 @@ class DAINPredictor(BasePredictor):
return sum([2**i for (i, v) in enumerate(diff.flatten()) if v])
hashes = {}
max_interp = 9
image_paths = sorted(glob.glob(os.path.join(paths, '*.png')))
for image_path in image_paths:
image = cv2.imread(image_path)
......@@ -283,7 +284,16 @@ class DAINPredictor(BasePredictor):
last_index = int(
hashed_paths[-1].split('/')[-1].split('.')[-2]) + 1
gap = 2 * (last_index - first_index) - 1
if gap > 9:
if gap > 2 * max_interp:
cut1 = len(hashed_paths) // 3
cut2 = cut1 * 2
for p in hashed_paths[1:cut1 - 1]:
os.remove(p)
for p in hashed_paths[cut1 + 1:cut2]:
os.remove(p)
for p in hashed_paths[cut2 + 1:]:
os.remove(p)
if gap > max_interp:
mid = len(hashed_paths) // 2
for p in hashed_paths[1:mid - 1]:
os.remove(p)
......
......@@ -43,16 +43,6 @@ def toImage(net_output):
return img
def mask2image(mask: np.array, format="HWC"):
H, W = mask.shape
canvas = np.zeros((H, W, 3), dtype=np.uint8)
for i in range(int(mask.max())):
color = np.random.rand(1, 1, 3) * 255
canvas += (mask == i)[:, :, None] * color.astype(np.uint8)
return canvas
PS_WEIGHT_URL = "https://paddlegan.bj.bcebos.com/models/psgan_weight.pdparams"
......@@ -81,6 +71,7 @@ class PreProcess:
self.down_ratio,
self.width_ratio)
np_image = np.array(image)
image_trans = self.transform(np_image)
mask = self.face_parser.parse(
np.float32(cv2.resize(np_image, (512, 512))))
mask = cv2.resize(mask.numpy(), (self.img_size, self.img_size),
......@@ -88,7 +79,8 @@ class PreProcess:
mask = mask.astype(np.uint8)
mask_tensor = paddle.to_tensor(mask)
lms = futils.dlib.landmarks(image, face) * self.img_size / image.width
lms = futils.dlib.landmarks(
image, face) / image_trans.shape[:2] * self.img_size
lms = lms.round()
P_np = generate_P_from_lmks(lms, self.img_size, self.img_size,
......@@ -96,10 +88,8 @@ class PreProcess:
mask_aug = generate_mask_aug(mask, lms)
image = self.transform(np_image)
return [
self.norm(image).unsqueeze(0),
self.norm(image_trans).unsqueeze(0),
np.float32(mask_aug),
np.float32(P_np),
np.float32(mask)
......@@ -212,6 +202,9 @@ class PSGANPredictor(BasePredictor):
image = postprocess(source_crop, image)
ref_img_name = os.path.split(reference_path)[1]
if not os.path.exists(self.output_path):
os.makedirs(sefl.output_path)
save_path = os.path.join(self.output_path,
'transfered_ref_' + ref_img_name)
image.save(save_path)
......@@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import numpy as np
import paddle
......
......@@ -12,7 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
import argparse
cur_path = os.path.abspath(os.path.dirname(__file__))
root_path = os.path.split(cur_path)[0]
sys.path.append(root_path)
from ppgan.utils.options import parse_args
from ppgan.utils.config import get_config
from ppgan.apps.psgan_predictor import PSGANPredictor
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册