tensor

eigenvalue decomposition of structure tensor in matlab

杀马特。学长 韩版系。学妹 提交于 2019-12-13 18:07:38
问题 I have a synthetic image. I want to do eigenvalue decomposition of local structure tensor (LST) of it for some edge detection purposes. I used the eigenvalues l1 , l2 and eigenvectors e1 , e2 of LST to generate an adaptive ellipse for each pixel of image. Unfortunately I get unequal eigenvalues l1 , l2 and so unequal semi-axes length of ellipse for homogeneous regions of my figure: However I get good response for a simple test image: I don't know what is wrong in my code: function [H,e1,e2,l1

PyTorch中Variable变量

半腔热情 提交于 2019-12-13 13:36:56
一、了解Variable 顾名思义,Variable就是 变量 的意思。实质上也就是可以变化的量,区别于int变量,它是一种可以变化的变量,这正好就符合了反向传播,参数更新的属性。 具体来说,在pytorch中的Variable就是一个存放会变化值的地理位置,里面的值会不停发生片花,就像一个装鸡蛋的篮子,鸡蛋数会不断发生变化。那谁是里面的鸡蛋呢,自然就是pytorch中的tensor了。(也就是说, pytorch都是有tensor计算的,而tensor里面的参数都是Variable的形式 )。如果用Variable计算的话,那返回的也是一个同类型的Variable。 【tensor 是一个多维矩阵】 用一个例子说明,Variable的定义: import torch from torch.autograd import Variable # torch 中 Variable 模块 tensor = torch.FloatTensor([[1,2],[3,4]]) # 把鸡蛋放到篮子里, requires_grad是参不参与误差反向传播, 要不要计算梯度 variable = Variable(tensor, requires_grad=True) print(tensor) “”" 1 2 3 4 [torch.FloatTensor of size 2x2] “”" print

Convert R code into Matlab

老子叫甜甜 提交于 2019-12-13 07:33:29
问题 I need to write in Matlab this portion of the package "tensor" which is written in R. Unfortunately I am not used to R code style. where A=matrix(sample(0:1, 2 * 3, replace = TRUE), 2, 3) here the code in R: A <- as.array(A) dimA <- dim(A) dnA <- dimnames(A) seqA <- seq(along=dimA) allA <- length(seqA) == length(alongA) permA <- c(seqA[-alongA], alongA) if (!all(seqA == permA)) A <- aperm(A, permA) dim(A) <- c( if (allA) 1 else prod(dimA[-alongA]), prod(dimA[alongA]) ) Thank you in advance

How to get a tensor's value in TensorFlow (without making another session)

人走茶凉 提交于 2019-12-13 03:56:45
问题 I'm finding a way to getting a tensor's value. In most case, the problem would be solved by calling "sess.run(target_op)". However, I want to know another way. I am editing the code downloaded from GitHub so there's already a session running code there. Without touching the session running part, is there any way to get some specific tensor value? In my case, the code is built for getting accuracy for image recognition. While session runs and doing the accuracy evaluation I also want to get

Keras tensors - Get values with indices coming from another tensor

别说谁变了你拦得住时间么 提交于 2019-12-12 13:12:15
问题 Suppose I have these two tensors: valueMatrix , shaped as (?, 3) , where ? is the batch size indexMatrix , shaped as (?, 1) I want to retrieve values from valueMatrix at the indices contained in indexMatrix . Example (pseudocode): valueMatrix = [[7,15,5],[4,6,8]] -- shape=(2,3) -- type=float indexMatrix = [[1],[0]] -- shape = (2,1) -- type=int I want from this example to do something like: valueMatrix[indexMatrix] --> returns --> [[15],[4]] I prefer Tensorflow over other backends, but the

Difference between tensor.permute and tensor.view in PyTorch?

空扰寡人 提交于 2019-12-12 08:36:25
问题 What is the difference between tensor.permute() and tensor.view() ? They seem to do the same thing. 回答1: View changes how the tensor is represented. For ex: a tensor with 4 elements can be represented as 4X1 or 2X2 or 1X4 but permute changes the axes. While permuting the data is moved but with view data is not moved but just reinterpreted. Below code examples may help you. a is 2x2 tensor/matrix. With the use of view you can read a as a column or row vector (tensor). But you can't transpose

Tensorflow 2.0 Object Detection API Demo Error int() argument must be a string, a bytes-like object or a number, not 'Tensor'

时间秒杀一切 提交于 2019-12-11 18:41:53
问题 I'm trying to implement the code from 'object_detection_tutorial.ipynb' on my local machine to change some parts and play around. This tutorial is a huge mess and I'm trying really hard to fix any problem I came across but for this one I had no clue. So, here I am. I'm using Windows 10 and Visual Studio 2019 Professional. Any package related to Tensorflow is up to date and I have another Machine Learning application running with no problems. I'd like to point out that, I converted this code

从头学pytorch(一):数据操作

心已入冬 提交于 2019-12-11 16:44:06
跟着 Dive-into-DL-PyTorch.pdf 从头开始学pytorch,夯实基础. Tensor创建 创建未初始化的tensor import torch x = torch.empty(5,3) print(x) 输出 tensor([[ 2.0909e+21, 3.0638e-41, -2.4612e-30], [ 4.5650e-41, 3.0638e-41, 1.7753e+28], [ 4.4339e+27, 1.3848e-14, 6.8801e+16], [ 1.8370e+25, 1.4603e-19, 6.8794e+11], [ 2.7253e+20, 3.0866e+29, 1.5835e-43]]) 创建随机初始化的tensor x = torch.rand(5,3) print(x) 输出 tensor([[0.7302, 0.0805, 0.9499], [0.9323, 0.2995, 0.2943], [0.7428, 0.8312, 0.6465], [0.7843, 0.7300, 0.7509], [0.4965, 0.1318, 0.9063]]) 创建全0的tensor,指定类型为long x = torch.zeros(5,3,dtype=torch.long) 输出 tensor([[0, 0, 0], [0, 0, 0],

how do I access to each elements in a tensor and producing a new tensor with that element's value?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 16:41:42
问题 I need to access each value in a tensor and then produce a new tensor with the extracted value in the first tensor. I received a suggestion in this post: how do I solve this error : AttributeError: 'NoneType' object has no attribute '_inbound_nodes'?1 and the proposed code is : rep=Kr.layers.Lambda(lambda x:Kr.backend.tile(x,[1, 28, 28, 1])) a_1 = Kr.layers.Lambda(lambda x: x[:, 1, 1, :])(wtm) a=rep(Kr.layers.Reshape([1,1,1])(a_1)) but when I feed the network with a test wtm in test phase and

Tensor multiplication w/o looping in Matlab

﹥>﹥吖頭↗ 提交于 2019-12-11 16:11:47
问题 I have a 3d array A, e.g. A=rand(N,N,K). I need an array B s.t. B(n,m) = norm(A(:,:,n)*A(:,:,m)' - A(:,:,m)*A(:,:,n)','fro')^2 for all indices n,m in 1:K. Here's the looping code: B = zeros(K,K); for n=1:K for m=1:K B(n,m) = norm(A(:,:,n)*A(:,:,m)' - A(:,:,m)*A(:,:,n)','fro')^2; end end I don't want to loop through 1:K. I can create an array An_x_mt of size N K x N K s.t. An_x_mt equals A(:,:,n)*A(:,:,m)' for all n,m in 1:K by An_x_mt = Ar*Ac_t; with Ac_t=reshape(permute(A,[2 1 3]),size(A,1),