Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
不是太高的手
SPTools
提交
95f290e9
S
SPTools
项目概览
不是太高的手
/
SPTools
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SPTools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
95f290e9
编写于
5月 26, 2020
作者:
小
小柒2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
自建鉴黄服务
上级
88e960d8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
66 addition
and
0 deletion
+66
-0
src/main/resources/python/models/1547856517/saved_model.pb
src/main/resources/python/models/1547856517/saved_model.pb
+0
-0
src/main/resources/python/models/1547856517/variables/variables.data-00000-of-00001
...models/1547856517/variables/variables.data-00000-of-00001
+0
-0
src/main/resources/python/models/1547856517/variables/variables.index
...ources/python/models/1547856517/variables/variables.index
+0
-0
src/main/resources/python/yellow.py
src/main/resources/python/yellow.py
+44
-0
src/main/resources/python/机器学习.txt
src/main/resources/python/机器学习.txt
+22
-0
未找到文件。
src/main/resources/python/models/1547856517/saved_model.pb
0 → 100644
浏览文件 @
95f290e9
文件已添加
src/main/resources/python/models/1547856517/variables/variables.data-00000-of-00001
0 → 100644
浏览文件 @
95f290e9
文件已添加
src/main/resources/python/models/1547856517/variables/variables.index
0 → 100644
浏览文件 @
95f290e9
文件已添加
src/main/resources/python/yellow.py
0 → 100644
浏览文件 @
95f290e9
import
sys
import
json
import
requests
from
PIL
import
Image
import
numpy
as
np
_IMAGE_SIZE
=
64
# TensorFlow-serving 调用地址,这里要替换成自己的,后面会讲到如何安装
SERVER_URL
=
'http://172.17.0.4:8501/v1/models/image:predict'
_LABEL_MAP
=
{
0
:
'drawings'
,
1
:
'hentai'
,
2
:
'neutral'
,
3
:
'porn'
,
4
:
'sexy'
}
def
standardize
(
img
):
mean
=
np
.
mean
(
img
)
std
=
np
.
std
(
img
)
img
=
(
img
-
mean
)
/
std
return
img
# 导入
def
load_image
(
image_path
):
img
=
Image
.
open
(
image_path
)
img
=
img
.
resize
((
_IMAGE_SIZE
,
_IMAGE_SIZE
))
img
.
load
()
data
=
np
.
asarray
(
img
,
dtype
=
"float32"
)
data
=
standardize
(
data
)
data
=
data
.
astype
(
np
.
float16
,
copy
=
False
)
return
data
# 分析
def
nsfw_predict
(
image_data
):
pay_load
=
json
.
dumps
({
"inputs"
:
[
image_data
.
tolist
()]})
response
=
requests
.
post
(
SERVER_URL
,
data
=
pay_load
)
data
=
response
.
json
()
outputs
=
data
[
'outputs'
]
predict_result
=
{
"classes"
:
_LABEL_MAP
.
get
(
outputs
[
'classes'
][
0
])}
predict_result
[
'probabilities'
]
=
{
_LABEL_MAP
.
get
(
i
):
l
for
i
,
l
in
enumerate
(
outputs
[
'probabilities'
][
0
])}
return
predict_result
if
__name__
==
'__main__'
:
image_data
=
load_image
(
sys
.
argv
[
1
])
predict
=
nsfw_predict
(
image_data
)
print
(
predict
)
src/main/resources/python/机器学习.txt
0 → 100644
浏览文件 @
95f290e9
docker run -d --name serving_image tensorflow/serving
# 2000 样本
docker cp /home/nsfw/data/models/ serving_image:/models/image
docker cp /home/nsfw/data/models/1547856517 serving_image:/models/image
docker exec -it serving_image /bin/bash
tensorflow_model_server --port=8500 --rest_api_port=8501 --model_name=image --model_base_path=/models/image
pip install pillow
pip install numpy
## 参考
https://www.cnblogs.com/weiyinfu/p/9928363.html
https://www.oschina.net/news/103861/nsfw-opensource
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录