最近在阅读《tensorflow实战google深度学习框架》,对里面讲到的内容,重点部分做下摘抄和笔记,以备后面查阅。部分内容为本人个人理解,如果错误,请指正,如果侵权,请联系删除,谢谢。转载请注明出处,谢谢。
将训练得到的embedding可视化
# Step 6:Visualize the embeddings.
# pylint:disable=missing-docstring
# Function todraw visualization of distance between embeddings.
defplot_with_labels(low_dim_embs, labels, filename):
assert low_dim_embs.shape[0] >=len(labels), 'More labels than embeddings'
plt.figure(figsize=(18, 18)) # in inches
for i, label in enumerate(labels):
x, y = low_dim_embs[i, :]
plt.scatter(x, y)
plt.annotate(label,
xy=(x, y),
xytext=(5, 2),
textcoords='offset points',
ha='right',
va='bottom')
plt.savefig(filename)
try:
# pylint: disable=g-import-not-at-top
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
#指定默认字体
plt.rcParams['font.sans-serif'] =['SimHei']
plt.rcParams['font.family']='sans-serif'
#解决负号'-'显示为方块的问题
plt.rcParams['axes.unicode_minus'] = False
tsne = TSNE(perplexity=30, n_components=2,init='pca', n_iter=5000, method='exact')
plot_only = 500
low_dim_embs =tsne.fit_transform(final_embeddings[:plot_only, :])
labels = [reverse_dictionary[i] for i inxrange(plot_only)]
plot_with_labels(low_dim_embs, labels,os.path.join(gettempdir(), 'tsne.png'))
exceptImportError as ex:
print('Please install sklearn, matplotlib,and scipy to show embeddings.')
print(ex)
Linux上编译tensorflow的jar包和so文件
以下编译命令在tensorflow根目录执行,文件路径是相对于tensorflow根目录而言
编译so:
bazel build -c opt//tensorflow/contrib/android:libtensorflow_inference.so \
--crosstool_top=//external:android/crosstool \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--cpu=armeabi-v7a
编译后文件位置:
bazel-bin/tensorflow/contrib/android/libtensorflow_inference.so
编译jar文件:
bazel build//tensorflow/contrib/android:android_tensorflow_inference_java
编译后文件位置:
bazel-bin/tensorflow/contrib/android/libandroid_tensorflow_inference_java.jar
作者:追逐丶
链接:https://www.jianshu.com/p/d3e2eced12b2
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。