Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
a123456jy
DeepMosaics
提交
b4d5c316
DeepMosaics
项目概览
a123456jy
/
DeepMosaics
与 Fork 源项目一致
Fork自
Hypo / DeepMosaics
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
DeepMosaics
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b4d5c316
编写于
5月 14, 2019
作者:
H
hypox64
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update to Pytorch 1.0
上级
346d19cb
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
416 addition
and
258 deletion
+416
-258
CleanMosaic.py
CleanMosaic.py
+1
-1
README.md
README.md
+4
-4
models/loadmodel.py
models/loadmodel.py
+1
-6
models/pix2pix_model.py
models/pix2pix_model.py
+389
-236
models/unet_model.py
models/unet_model.py
+1
-1
models/unet_parts.py
models/unet_parts.py
+8
-1
options/addmosaic_options.py
options/addmosaic_options.py
+1
-1
options/cleanmosaic_options.py
options/cleanmosaic_options.py
+1
-1
util/image_processing.py
util/image_processing.py
+2
-2
util/mosaic.py
util/mosaic.py
+8
-5
未找到文件。
CleanMosaic.py
浏览文件 @
b4d5c316
...
...
@@ -17,7 +17,7 @@ opt = CleanOptions().getparse()
def
get_mosaic_position
(
img_origin
):
mask
=
runmodel
.
run_unet_rectim
(
img_origin
,
net_mosaic_pos
,
use_gpu
=
opt
.
use_gpu
)
mask
=
impro
.
mask_threshold
(
mask
,
10
,
128
)
x
,
y
,
size
,
area
=
impro
.
boundingSquare
(
mask
,
threshold
=
128
,
Ex_mul
=
1.5
)
x
,
y
,
size
,
area
=
impro
.
boundingSquare
(
mask
,
Ex_mul
=
1.5
)
rat
=
min
(
img_origin
.
shape
[:
2
])
/
128.0
x
,
y
,
size
=
int
(
rat
*
x
),
int
(
rat
*
y
),
int
(
rat
*
size
)
return
x
,
y
,
size
...
...
README.md
浏览文件 @
b4d5c316
...
...
@@ -10,9 +10,9 @@ The code do not include the part of training, I will finish it in my free time.
## Prerequisites
-
Linux, (I didn't try this code on Windows or Mac OS)
-
Python 3.
5
+
-
Python 3.
6
+
-
ffmpeg
-
Pytorch
0.4
[
(Pytorch 1.0+ is available)
](
https://github.com/HypoX64/DeepMosaics
)
-
Pytorch
1.0+
[
(Old version codes)
](
https://github.com/HypoX64/DeepMosaics/tree/Pytorch0.4
)
-
CPU or NVIDIA GPU + CUDA CuDNN
## Getting Started
...
...
@@ -23,8 +23,8 @@ cd DeepMosaics
```
### Get pre_trained models and test video
You can download pre_trained models and test video and replace the files in the project.
<br>
[
[Google Drive]
](
https://drive.google.com/open?id=1
PXt3dE9Eez2xUqpemLJutwTCC0tW-D2g
)
[
[百度云,提取码
z8vz]
](
https://pan.baidu.com/s/1Wi8T6PE4ExTjrHVQhv3rJA
)
[
[Google Drive]
](
https://drive.google.com/open?id=1
0nARsiZoZGcaKw40nQu9fJuRp1oeabPs
)
[
[百度云,提取码
7thu]
](
https://pan.baidu.com/s/1IG4bdIiIC9PH9-oEyae5Sg
)
### Dependencies
This code depends on numpy, scipy, opencv-python, torchvision, available via pip install.
...
...
models/loadmodel.py
浏览文件 @
b4d5c316
...
...
@@ -4,9 +4,7 @@ from .unet_model import UNet
def
pix2pix
(
model_path
,
G_model_type
,
use_gpu
=
True
):
gpu_ids
=
[]
if
use_gpu
:
gpu_ids
=
[
0
]
netG
=
define_G
(
3
,
3
,
64
,
G_model_type
,
norm
=
'instance'
,
init_type
=
'normal'
,
gpu_ids
=
gpu_ids
)
netG
=
define_G
(
3
,
3
,
64
,
G_model_type
,
norm
=
'batch'
,
init_type
=
'normal'
,
gpu_ids
=
gpu_ids
)
netG
.
load_state_dict
(
torch
.
load
(
model_path
))
netG
.
eval
()
if
use_gpu
:
...
...
@@ -20,6 +18,3 @@ def unet(model_path,use_gpu = True):
if
use_gpu
:
net
.
cuda
()
return
net
# def unet():
\ No newline at end of file
models/pix2pix_model.py
浏览文件 @
b4d5c316
此差异已折叠。
点击以展开。
models/unet_model.py
浏览文件 @
b4d5c316
...
...
@@ -29,4 +29,4 @@ class UNet(nn.Module):
x
=
self
.
up3
(
x
,
x2
)
x
=
self
.
up4
(
x
,
x1
)
x
=
self
.
outc
(
x
)
return
F
.
sigmoid
(
x
)
return
torch
.
sigmoid
(
x
)
models/unet_parts.py
浏览文件 @
b4d5c316
...
...
@@ -45,7 +45,14 @@ class down(nn.Module):
x
=
self
.
mpconv
(
x
)
return
x
class
Upsample
(
nn
.
Module
):
def
__init__
(
self
,
scale_factor
):
super
(
Upsample
,
self
).
__init__
()
self
.
scale_factor
=
scale_factor
def
forward
(
self
,
x
):
return
F
.
interpolate
(
x
,
scale_factor
=
self
.
scale_factor
,
mode
=
'bilinear'
,
align_corners
=
True
)
F
.
interpolate
class
up
(
nn
.
Module
):
def
__init__
(
self
,
in_ch
,
out_ch
,
bilinear
=
True
):
super
(
up
,
self
).
__init__
()
...
...
@@ -53,7 +60,7 @@ class up(nn.Module):
# would be a nice idea if the upsampling could be learned too,
# but my machine do not have enough memory to handle all those weights
if
bilinear
:
self
.
up
=
nn
.
Upsample
(
scale_factor
=
2
,
mode
=
'bilinear'
,
align_corners
=
True
)
self
.
up
=
Upsample
(
scale_factor
=
2
)
else
:
self
.
up
=
nn
.
ConvTranspose2d
(
in_ch
//
2
,
in_ch
//
2
,
2
,
stride
=
2
)
...
...
options/addmosaic_options.py
浏览文件 @
b4d5c316
...
...
@@ -18,7 +18,7 @@ class AddOptions():
self
.
parser
.
add_argument
(
'--mask_extend'
,
type
=
int
,
default
=
20
,
help
=
'more mosaic area'
)
self
.
parser
.
add_argument
(
'--mask_threshold'
,
type
=
int
,
default
=
64
,
help
=
'threshold of recognize mosaic position 0~255'
)
self
.
parser
.
add_argument
(
'--output_size'
,
type
=
int
,
default
=
0
,
help
=
'size of output file,if 0 -> origin'
)
self
.
parser
.
add_argument
(
'--tempimage_type'
,
type
=
str
,
default
=
'
jp
g'
,
help
=
'type of temp image, png | jpg, png is better but occupy more storage space'
)
self
.
parser
.
add_argument
(
'--tempimage_type'
,
type
=
str
,
default
=
'
pn
g'
,
help
=
'type of temp image, png | jpg, png is better but occupy more storage space'
)
self
.
initialized
=
True
def
getparse
(
self
):
...
...
options/cleanmosaic_options.py
浏览文件 @
b4d5c316
...
...
@@ -18,7 +18,7 @@ class CleanOptions():
help
=
'name of model use to find mosaic position'
)
self
.
parser
.
add_argument
(
'--no_feather'
,
action
=
'store_true'
,
help
=
'if true, no edge feather,but run faster'
)
self
.
parser
.
add_argument
(
'--medfilt_num'
,
type
=
int
,
default
=
11
,
help
=
'medfilt window of mosaic movement in the video'
)
self
.
parser
.
add_argument
(
'--tempimage_type'
,
type
=
str
,
default
=
'
jp
g'
,
help
=
'type of temp image, png | jpg, png is better but occupy more storage space'
)
self
.
parser
.
add_argument
(
'--tempimage_type'
,
type
=
str
,
default
=
'
pn
g'
,
help
=
'type of temp image, png | jpg, png is better but occupy more storage space'
)
# self.parser.add_argument('--zoom_multiple', type=float, default=1.0,help='zoom video')
self
.
initialized
=
True
...
...
util/image_processing.py
浏览文件 @
b4d5c316
...
...
@@ -4,7 +4,7 @@ import numpy as np
def
resize
(
img
,
size
):
h
,
w
=
img
.
shape
[:
2
]
if
min
(
h
,
w
)
==
size
:
if
np
.
min
((
w
,
h
)
)
==
size
:
return
img
if
w
>=
h
:
res
=
cv2
.
resize
(
img
,(
int
(
size
*
w
/
h
),
size
))
...
...
@@ -62,7 +62,7 @@ def mergeimage(img1,img2,orgin_image):
result_img
=
cv2
.
add
(
new_img1
,
new_img2
)
return
result_img
def
boundingSquare
(
mask
,
threshold
,
Ex_mul
):
def
boundingSquare
(
mask
,
Ex_mul
):
# thresh = mask_threshold(mask,10,threshold)
area
=
mask_area
(
mask
)
if
area
==
0
:
...
...
util/mosaic.py
浏览文件 @
b4d5c316
...
...
@@ -6,6 +6,7 @@ from .image_processing import resize,ch_one2three,mask_area
def
addmosaic
(
img
,
mask
,
n
,
out_size
=
0
,
model
=
'squa_avg'
):
n
=
int
(
n
)
if
out_size
:
img
=
resize
(
img
,
out_size
)
h
,
w
=
img
.
shape
[:
2
]
...
...
@@ -59,22 +60,24 @@ def random_mosaic_mod(img,mask,n):
return
img
def
random_mosaic
(
img
,
mask
):
img
=
resize
(
img
,
512
)
#
img = resize(img,512)
h
,
w
=
img
.
shape
[:
2
]
mask
=
cv2
.
resize
(
mask
,(
w
,
h
))
alpha
=
np
.
min
((
w
,
h
))
/
512
#area_avg=5925*4
try
:
area
=
mask_area
(
mask
)
except
:
area
=
0
area
=
area
/
(
alpha
*
alpha
)
if
area
>
50000
:
img_mosaic
=
random_mosaic_mod
(
img
,
mask
,
random
.
randint
(
14
,
26
))
img_mosaic
=
random_mosaic_mod
(
img
,
mask
,
alpha
*
random
.
uniform
(
16
,
28
))
elif
20000
<
area
<=
50000
:
img_mosaic
=
random_mosaic_mod
(
img
,
mask
,
random
.
randint
(
10
,
18
))
img_mosaic
=
random_mosaic_mod
(
img
,
mask
,
alpha
*
random
.
uniform
(
12
,
20
))
elif
5000
<
area
<=
20000
:
img_mosaic
=
random_mosaic_mod
(
img
,
mask
,
random
.
randint
(
8
,
14
))
img_mosaic
=
random_mosaic_mod
(
img
,
mask
,
alpha
*
random
.
uniform
(
8
,
15
))
elif
0
<=
area
<=
5000
:
img_mosaic
=
random_mosaic_mod
(
img
,
mask
,
random
.
randint
(
4
,
8
))
img_mosaic
=
random_mosaic_mod
(
img
,
mask
,
alpha
*
random
.
uniform
(
4
,
10
))
else
:
pass
return
img_mosaic
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录