TensorFlow
typeConversion
borgWarp
#migrated

TensorFlow > stringリストをTensor objectsに変換する > names_tf = ops.convert_to_tensor(names_str)

More than 1 year has passed since last update.
動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 14.04 LTS desktop amd64
TensorFlow v0.11
cuDNN v5.1 for Linux
CUDA v8.0
Python 2.7.6
IPython 5.1.0 -- An enhanced Interactive Python.

Deep LearningのフレームワークTensorFlowを学習中。

https://ischlag.github.io/2016/06/19/tensorflow-input-pipeline-example/

上記のリンクでstringリストをTensor objectsに変換する方法が紹介されていた。 

試してみた。

string_to_tensor.py
from tensorflow.python.framework import ops
from tensorflow.python.framework import dtypes

names_str = [ 'Janeway', 'Tuvok', '7of9' ]

names_tf = ops.convert_to_tensor(names_str, dtype=dtypes.string)

print(names_tf)
結果
$ python string_to_tensor.py 
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally
Tensor("Const:0", shape=(3,), dtype=string)