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

查看:37
本文介绍了如何将 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天全站免登陆