tensor

Eigen::Tensor, how to access matrix from Tensor

夙愿已清 提交于 2019-12-03 03:48:16
I have the following Eigen Tensor: Eigen::Tensor<float, 3> m(3,10,10); I want to access the 1st matrix. In numpy I would do it as such m(0,:,:) How would I do this in Eigen You can access parts of a tensor using .slice(...) or .chip(...) . Do this to access the first matrix, equivalent to numpy m(0,:,:) : Eigen::Tensor<double,3> m(3,10,10); //Initialize m.setRandom(); //Set random values Eigen::array<long,3> offset = {0,0,0}; //Starting point Eigen::array<long,3> extent = {1,10,10}; //Finish point std::cout << m.slice(offset, extent).reshape(Eigen::array<long,2>{10,10}) << std::endl; //Reshape

TensorFlow: generating a random constant

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In ipython I imported tensorflow as tf and numpy as np and created an TensorFlow InteractiveSession . When I am running or initializing some normal distribution with numpy input, everything runs fine: some_test = tf.constant(np.random.normal(loc=0.0, scale=1.0, size=(2, 2))) session.run(some_test) Returns: array([[-0.04152317, 0.19786302], [-0.68232622, -0.23439092]]) Just as expected. ...but when I use the Tensorflow normal distribution function: some_test = tf.constant(tf.random_normal([2, 2], mean=0.0, stddev=1.0, dtype=tf.float32))

How to get the dimensions of a tensor (in TensorFlow) at graph construction time?

时间秒杀一切 提交于 2019-12-03 03:03:10
问题 I am trying an Op that is not behaving as expected. graph = tf.Graph() with graph.as_default(): train_dataset = tf.placeholder(tf.int32, shape=[128, 2]) embeddings = tf.Variable( tf.random_uniform([50000, 64], -1.0, 1.0)) embed = tf.nn.embedding_lookup(embeddings, train_dataset) embed = tf.reduce_sum(embed, reduction_indices=0) So I need to know the dimensions of the Tensor embed . I know that it can be done at the run time but it's too much work for such a simple operation. What's the easier

动手深度学习4-线性回归的pytorch简洁实现

微笑、不失礼 提交于 2019-12-03 02:47:11
导入同样导入之前的包或者模块 生成数据集 通过pytorch读取数据 定义模型 初始化模型 定义损失函数 定义优化算法 训练模型 小结 本节利用pytorch中的模块,生成一个更加简洁的代码来实现同样的功能 导入同样导入之前的包或者模块 %matplotlib inline import torch from IPython import display from matplotlib import pyplot as plt import numpy as np import random 生成数据集 num_inputs =2 ## 特征数量 num_examples=1000 # 样本量 true_w=[2,-3.4] # 真实的权重系数 true_b=4.2 # 真实的偏置量 features = torch.randn(num_examples,num_inputs,dtype=torch.float32) # 生成随机的特征 labels = true_w[0]*features[:,0]+true_w[1]*features[:,1]+true_b # 生成随机的标签 labels += torch.tensor(np.random.normal(0,0.01,size=labels.size()),dtype=torch.float32) #在标签上加上随机噪声项

OOM when allocating tensor

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: How do I solve the problem of ResourceExhaustedError: OOM when allocating tensor? ResourceExhaustedError (see above for traceback): OOM when allocating tensor with shape[10000,32,28,28] I included nearly all the code learning_rate = 0.0001 epochs = 10 batch_size = 50 # declare the training data placeholders # input x - for 28 x 28 pixels = 784 - this is the flattened image data that is drawn from # mnist.train.nextbatch() x = tf . placeholder ( tf . float32 , [ None , 784 ]) # dynamically reshape the input x_shaped = tf . reshape (

Does tensorflow map_fn support taking more than one tensor?

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Does tf.map_fn support taking more than one tensors as is supported by python's native map function (example provided below)? a = [1,2,3,4] b = [17,12,11,10] print(map(lambda x,y:x+y, a,b)) # ==> [18, 14, 14, 14] 回答1: Not natively, but here's a quick function that achieves it: def map(fn, arrays, dtype=tf.float32): # assumes all arrays have same leading dim indices = tf.range(tf.shape(arrays[0])[0]) out = tf.map_fn(lambda ii: fn(*[array[ii] for array in arrays]), indices, dtype=dtype) return out # example: batch affine tranformation x = tf

How do I pass an OpenCV Mat into a C++ Tensorflow graph?

匿名 (未验证) 提交于 2019-12-03 01:58:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: In Tensorflow C++ I can load an image file into the graph using tensorflow :: Node * file_reader = tensorflow :: ops :: ReadFile ( tensorflow :: ops :: Const ( IMAGE_FILE_NAME , b . opts ()), b . opts (). WithName ( input_name )); tensorflow :: Node * image_reader = tensorflow :: ops :: DecodePng ( file_reader , b . opts (). WithAttr ( "channels" , 3 ). WithName ( "png_reader" )); tensorflow :: Node * float_caster = tensorflow :: ops :: Cast ( image_reader , tensorflow :: DT_FLOAT , b . opts (). WithName ( "float_caster" ));

PermissionError: [Errno 13] Permission denied when doing input_data.read_data_sets(..)

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I pip installed Tensor Flow so I don't have tensorflow.examples so I got the souce input_data from GitHub. How ever I am getting the following error. PermissionError: [Errno 13] Permission denied: 'C:\Users\Nikhil\AppData\Local\Temp\tmp5gr8f26y' This is my code. import input_data mnist = input_data.read_data_sets("/MNIST_data/", one_hot = True) How do I solve this problem? There is another thread dealing with the exact same issue but that solution did not solve my problem. What should I do now? The input_data.py file is in my projects's

Tensorflow keras with tf dataset input

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm new to tensorflow keras and dataset. Can anyone help me understand why the following code doesn't work? import tensorflow as tf import tensorflow . keras as keras import numpy as np from tensorflow . python . data . ops import dataset_ops from tensorflow . python . data . ops import iterator_ops from tensorflow . python . keras . utils import multi_gpu_model from tensorflow . python . keras import backend as K data = np . random . random (( 1000 , 32 )) labels = np . random . random (( 1000 , 10 )) dataset = tf . data . Dataset

AttributeError: &#039;Tensor&#039; object has no attribute &#039;_keras_history&#039;

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I looked for all the "'Tensor' object has no attribute ***" but none seems related to Keras (except for TensorFlow: AttributeError: 'Tensor' object has no attribute 'log10' which didn't help)... I am making a sort of GAN (Generative Adversarial Networks). Here you can find the structure. Layer (type) Output Shape Param # Connected to _____________________________________________________________________________ input_1 (InputLayer) (None, 30, 91) 0 _____________________________________________________________________________ model_1 (Model)