如何将numpy数组转换为标准TensorFlow格式? [英] How to convert numpy arrays to standard TensorFlow format?

查看:1134
本文介绍了如何将numpy数组转换为标准TensorFlow格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个numpy数组:

I have two numpy arrays:

  • 其中包含验证码图片
  • 另一个包含相应标签的标签(单向矢量格式)

我想将它们加载到TensorFlow中,以便可以使用神经网络对其进行分类.怎么做?

numpy数组需要具有什么形状?

What shape do the numpy arrays need to have?

其他信息-我的图像每个都是60(高)乘160(宽)像素,每个图像都有5个字母数字字符.这是一个示例图像:

Additional Info - My images are 60 (height) by 160 (width) pixels each and each of them have 5 alphanumeric characters. Here is a sample image:

每个标签都是5 x 62的数组.

Each label is a 5 by 62 array.

推荐答案

您可以使用tf.convert_to_tensor():

import tensorflow as tf
import numpy as np

data = [[1,2,3],[4,5,6]]
data_np = np.asarray(data, np.float32)

data_tf = tf.convert_to_tensor(data_np, np.float32)

sess = tf.InteractiveSession()  
print(data_tf.eval())

sess.close()

以下是此方法的文档的链接:

Here's a link to the documentation for this method:

https://www.tensorflow.org/api_docs/python/tf/convert_to_tensor

这篇关于如何将numpy数组转换为标准TensorFlow格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆