<jupyter_start><jupyter_text>挂载谷歌云端硬盘：<jupyter_code>from google.colab import drive

drive.mount('/content/gdrive')<jupyter_output>Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdocs.test%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.photos.readonly%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fpeopleapi.readonly&response_type=code

Enter your authorization code:
··········
Mounted at /content/gdrive<jupyter_text>切换当前目录为Google云端硬盘的项目文件夹：<jupyter_code>import os

project_path = '/content/gdrive/My Drive/nvidia'  #change dir to your project folder
os.chdir(project_path)  #change dir<jupyter_output><empty_output><jupyter_text>确定CUDA，Ubuntu，TensorFlow的版本：<jupyter_code>!nvcc --version
!cat /etc/issue
import tensorflow as tf
print(tf.__version__)<jupyter_output>nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130
Ubuntu 18.04.2 LTS \n \l

1.13.1<jupyter_text>下载TensorRT，由于nvidia官网下载需要注册、登录等诸多步骤，而且Google云端硬盘的上传速度比较慢，所以我放了一份拷贝到dropbox中，从dropbox下载要快得多：<jupyter_code>!wget -O nv-tensorrt-repo-ubuntu1804-cuda10.0-trt5.1.2.2-rc-20190227_1-1_amd64.deb https://www.dropbox.com/s/45pz13r4e8ip4bl/nv-tensorrt-repo-ubuntu1804-cuda10.0-trt5.1.2.2-rc-20190227_1-1_amd64.deb?dl=0
!dpkg -i nv-tensorrt-repo-ubuntu1804-cuda10.0-trt5.1.2.2-rc-20190227_1-1_amd64.deb
!apt-key add /var/nv-tensorrt-repo-cuda10.0-trt5.1.2.2-rc-20190227/7fa2af80.pub
!apt-get update
!apt-get install -y --no-install-recommends libnvinfer5=5.1.2-1+cuda10.0
!apt-get install -y --no-install-recommends libnvinfer-dev=5.1.2-1+cuda10.0
!apt-get install tensorrt
!apt-get install python3-libnvinfer-dev
!apt-get install uff-converter-tf<jupyter_output>Selecting previously unselected package nv-tensorrt-repo-ubuntu1804-cuda10.0-trt5.1.2.2-rc-20190227.
(Reading database ... 
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 130824 files and directories currently installed.)
Preparing to unpack nv-tensorrt-repo-ubuntu1804-cuda10.0-trt5.1.2.2-rc-20190227_1-1_amd64.deb ...
Unpacking nv-tensorrt-repo-ubuntu1804-cuda10.0-trt5.1.2.2-rc-20190227 (1-1) ...
Setting up nv-tensorrt-repo-ubuntu1804-cuda10.0-trt5.1.2.2-rc-20190227 (1-1) ...
OK
Get:1 file:/var/nv-te[...]<jupyter_text>克隆open_nsfw的tensorflow版本代码库：<jupyter_code>!git clone https://github.com/mogoweb/tensorflow-open_nsfw.git
os.chdir(os.path.join(project_path, "tensorflow-open_nsfw"))<jupyter_output><empty_output><jupyter_text>判断单个图片是否色情图片，请根据实际情况替换后面的图片路径：<jupyter_code>!python classify_nsfw.py -m data/open_nsfw-weights.npy ../test/porn/23241c38-a7f7-44c0-9faa-4bed8dfff3a4.jpg<jupyter_output>2019-05-20 08:36:45.008917: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2200000000 Hz
2019-05-20 08:36:45.009204: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x32c71e0 executing computations on platform Host. Devices:
2019-05-20 08:36:45.009241: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>
2019-05-20 08:36:45.242438: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:998] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-05-20 08:36:45.242999: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x32c6dc0 executing computations on platform CUDA. Devices:
2019-05-20 08:36:45.243028: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): Tesla T4, Compute Capability 7.5
2019-05-20 08:36:45.243365: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found de[...]<jupyter_text>导出tensorflow模型图：<jupyter_code>!python tools/export_graph.py -m ./data/open_nsfw-weights.npy -i tensor -f ./data/models/<jupyter_output>2019-05-20 08:58:43.129808: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2200000000 Hz
2019-05-20 08:58:43.130011: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x27c6520 executing computations on platform Host. Devices:
2019-05-20 08:58:43.130039: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>
2019-05-20 08:58:43.305385: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:998] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-05-20 08:58:43.305906: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x27c5e40 executing computations on platform CUDA. Devices:
2019-05-20 08:58:43.305937: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): Tesla T4, Compute Capability 7.5
2019-05-20 08:58:43.306294: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found de[...]<jupyter_text>判断测试集图片，图片位于指定目录下：<jupyter_code>!python opt/benchmark_classify_nsfw.py -i ../test/porn -m ./data/models/frozen_open_nsfw.pb<jupyter_output>WARNING:tensorflow:From /content/gdrive/My Drive/nvidia/tensorflow-open_nsfw/opt/nsfw_trt_utils.py:7: FastGFile.__init__ (from tensorflow.python.platform.gfile) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.gfile.GFile.
2019-05-20 09:38:23.213304: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2200000000 Hz
2019-05-20 09:38:23.213517: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x2812260 executing computations on platform Host. Devices:
2019-05-20 09:38:23.213568: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>
2019-05-20 09:38:23.370835: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:998] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-05-20 09:38:23.371418: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x2811e40 executing computatio[...]
{'fraction_non_alphanumeric': 0.13346257083209068, 'fraction_numerical': 0.1309275275872353, 'mean_word_length': 5.569049951028403, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 3, 'lorem ipsum': 0, 'www.': 5, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '23246', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 3252, 'n_tokens_neox': 2731, 'n_words': 467, 'path': 'tensorRT_open_nsfw.ipynb', 'repo_name': 'mogoweb/tensorflow-open_nsfw', 'size': '6706'}