pytorch

Pytorch RuntimeError: Expected object of device type cuda but got device type cpu for argument #1 'self' in call to _th_index_select

折月煮酒 提交于 2021-02-11 14:35:05
问题 I am training a model that takes tokenized strings which are then passed through an embedding layer and an LSTM thereafter. However, there seems to be an error in the input, as it does not pass through the embedding layer. class DrugModel(nn.Module): def __init__(self, input_dim, output_dim, hidden_dim, drug_embed_dim, lstm_layer, lstm_dropout, bi_lstm, linear_dropout, char_vocab_size, char_embed_dim, char_dropout, dist_fn, learning_rate, binary, is_mlp, weight_decay, is_graph, g_layer, g

How I can swap 3 dimensions with each other in Pytorch?

只谈情不闲聊 提交于 2021-02-11 13:57:34
问题 I have a a= torch.randn(28, 28, 8) and I want to swap the dimensions of the tensor and move the third dimension to the first place, first one to the second place and the second one to the third place. I used b = a.transpose(2, 0, 1) , but I received this error: TypeError: transpose() received an invalid combination of arguments - got (int, int, int), but expected one of: * (name dim0, name dim1) * (int dim0, int dim1) Should I use transpose several times, each time only to swap two dimensions

深度学习实现安全帽佩戴的检测

眉间皱痕 提交于 2021-02-11 12:49:01
向AI转型的程序员都关注了这个号 👇👇👇 机器学习AI算法工程 公众号:datayx 01. 概述 对于图像识别,采用传统的算法(opencv的一些算法),判断形状、颜色等等,我们在实验室和办公场所做测试,效果还不错,和容易识别出来。一旦到了工业现场,图像完全不行,连人和车都识别不出来。在不同光线下不论采用什么颜色空间(RGB、HSV什么)都无法分离出合理的色彩,更不要提判断和检测了。有感于实际的现场环境,决定放弃传统的算法,拿起深度学习的工具,来搞定这个项目。 02. 数据准备 高大上的人工智能背后,一定是苦逼的数据准备,深度学习的模型,需要成千上万的训练和测试数据,这些数据的采集和整理,还有数据的清洗都是体力活啊。 当然,我还是没傻到一张张去拍照片。我通过现场的摄像头做了视频采集,然后拿到录像,做了一个代码从录像中找到人,再把人的上半部分处理一下,变成标准格式的图片。这样子,2-3天的录像就可以产生几十万张图片了,看来训练集的问题解决了。 采用SSD的算法(用于物体检测的深度学习主流算法之一)检测出图片中的人。 这样就可以建立自己的训练集: train和test (带不带帽子的标注需要人工去做... 这个还是很苦逼) 03. 搭建模型 考虑到标准的图片只有128*128,特征不是很多,就动手搭建一个不算深的深度学习模型,采用卷积神经网络处理图形特征,搞过cnn的同学会觉得so

GitHub排名TOP30的机器学习开源项目

让人想犯罪 __ 提交于 2021-02-11 08:32:25
对于机器学习者来说,阅读开源代码并基于代码构建自己的项目,是一个非常有效的学习方法。看看以下这些Github上平均star为3558的开源项目,你错了哪些? 1. FastText:快速文本表示和文本分类库(Github上有11786颗星,贡献者Facebook Research) 源码链接:https://github.com/facebookresearch/MUSE 2. Deep-photo-styletransfer:“Deep Photo Style Transfer” 这篇论文的源码和数据。(GitHub 9747颗星,论文来自于康奈尔大学的Fujun Luan) 源码链接:https://github.com/luanfujun/deep-photo-styletransfer 3. 用Python和命令行来实现的最简单的面部识别API(GitHub 8672颗星,贡献者Adam Geitgey) 源码链接:https://github.com/ageitgey/face_recognition 4. Magenta:利用机器智能生成音乐和美术艺术品(GitHub 8113颗星) 源码链接:https://github.com/tensorflow/magenta 5. Sonnet:基于TensorFlow的神经网络库(GitHub 573颗星

Pytorch nn Module generalization

不问归期 提交于 2021-02-11 06:20:37
问题 Let us take a look at the simple class: class Temp1(nn.Module): def __init__(self, stateSize, actionSize, layers=[10, 5], activations=[F.tanh, F.tanh] ): super(Temp1, self).__init__() self.layer1 = nn.Linear(stateSize, layers[0]) self.layer2 = nn.Linear(layers[0], layers[1]) self.fcFinal = nn.Linear( layers[1], actionSize ) return This is a fairly straight forward pytorch module. It creates a simple sequential dense network. If we check its hidden parameters, we see the following: t1 = Temp1

Pytorch nn Module generalization

∥☆過路亽.° 提交于 2021-02-11 06:20:18
问题 Let us take a look at the simple class: class Temp1(nn.Module): def __init__(self, stateSize, actionSize, layers=[10, 5], activations=[F.tanh, F.tanh] ): super(Temp1, self).__init__() self.layer1 = nn.Linear(stateSize, layers[0]) self.layer2 = nn.Linear(layers[0], layers[1]) self.fcFinal = nn.Linear( layers[1], actionSize ) return This is a fairly straight forward pytorch module. It creates a simple sequential dense network. If we check its hidden parameters, we see the following: t1 = Temp1

Where is torch.cholesky and how torch refers to its methods?

坚强是说给别人听的谎言 提交于 2021-02-11 05:57:29
问题 I'm doing some research into Cholesky decomposition, which requires some insights into how torch.cholesky works. After a while of grep-ing and searching through ATen, I got stuck at TensorMethods.h, which interestingly has this following code: inline Tensor Tensor::cholesky(bool upper) const { #ifdef USE_STATIC_DISPATCH return TypeDefault::cholesky(const_cast<Tensor&>(*this), upper); #else static c10::OperatorHandle op = c10::Dispatcher::singleton().findSchema({"aten::cholesky", ""}).value();

TensorFlow与PyTorch对比

六月ゝ 毕业季﹏ 提交于 2021-02-11 03:15:52
用TensorFlow还是PyTorch?从TensorFlow开始学起还是PyTorch?在一年前,这个问题毫无争议,当然是TensorFlow. 但时过境迁,现在的情况大不一样了,下面就来分析对比一下这两个主流框架。 首先看一下最近的统计数据,下图的数据是从arxiv论文中统计得到的。上面的黄线是TensorFlow的使用比例,下面的红线是PyTorch的使用比例,可以看出,最近的数据两者已经不差上下,甚至红线PyTorch在2019.6要略胜一筹。 右边的条形图是从1月到6月的累计数据,TensorFlow占比还是要略高一点,但是23%的增长率明显要低于PyTorch的194%.也就是说,现在TensorFlow和PyTorch在学术界的 使用率上来说已经不差上下了 。 来源:https://www.oreilly.com/ideas/one-simple-graphic-researchers-love-pytorch-and-tensorflow 决定一个框架的使用率有哪些因素呢?我总结有以下四个方面: 易用性 速度 算子数量 开源模型 第一是 易用性 。PyTorch自从2018年12月PyTorch 1.0 stable版本正式发布以来,只有半年多的时间,能迅速增长易用性功不可没。PyTorch的易用性一方面是debug简单,可以直接设置断点查看各个tensor的值

TensorFlow or PyTorch

别来无恙 提交于 2021-02-11 02:29:06
既然你已经读到了这篇文章,我就断定你已经开始了你的深度学习之旅了,并且对人造神经网络的研究已经有一段时间了;或者也许你正打算开始你的学习之旅。无论是哪一种情况,你都是因为发现你陷入了困惑中,才找到了这篇文章。你可能查询浏览了各种各样的深度学习的框架和库,但是其中有两个比较突出,他们是两个最流行的深度学习库:TensorFlow 和 PyTorch。你没有办法指出这两个库有什么本质的不同,不用担心!我将在这网络上无休止的存储空间中添加一篇新的文章,也许可以帮你弄清楚一些问题。我将简要的快速的给出你五点内容。仅仅是五点,那么,让我们开始吧! 第一点:尽管 TensorFlow 和 PyTorch 都是开源的,但是他们是由两个不同的公司创建的。TensorFlow 是由 Google 基于 Theano 开发的,而 PyTorch 是由 Facebook 基于 Torch 开发的。 第二点:这两个框架最大的不同是他们定义计算图的方式不同。TensorFlow 定义一个静态图,而 PyTorch 定义动态图,这是什么意思呢?意思就是在 TensorFlow 中,你必须首先定义整个计算图,然后运行你的机器学习模型。但是在 PyTorch 中,你可以在运行的过程中,定义或控制你的图,当在神经网络中使用变长的输入时,这是非常有用的。 第三点:TensorFlow 比 PyTorch

I want to run Libtorch (Pytorch C++ Frontend) in OpenFrameworks

╄→гoц情女王★ 提交于 2021-02-10 18:41:57
问题 All. I want to run Libtorch (Pytorch C++ Frontend) in OpenFrameworks. LibTorch Site: https://pytorch.org/tutorials/advanced/cpp_frontend.html If LibTorch runs in OpenFrameworks, it will be very powerful Deep Solution IDE (deep learning + GUI Production for OSX, Win10, & Linux). But I can’t include <torch/torch.h> in XCode. At CMake method, CMakeLists.txt is like this: cmake_minimum_required(VERSION 3.0 FATAL_ERROR) project(dcgan) find_package(Torch REQUIRED) add_executable(dcgan dcgan.cpp)