theano

Convert einsum computation to dot product to be used in Theano

大兔子大兔子 提交于 2019-12-01 06:28:38
I have just recently learned about np.einsum and quickly became addicted to it. But it seems that theano doesn't have an equivalent function so I need to convert my numpy code to theano somehow. How can I write the following computation in theano? IX=np.einsum('ijk,lj->ilk',p1,KX) You only need to rearrange your axes to get this to work: >>> import numpy as np >>> a = np.random.rand(3, 4, 5) >>> b = np.random.rand(5, 6) >>> np.allclose(np.einsum('ikj,jl->ikl', a, b), np.dot(a, b)) So with that in mind: >>> a = np.random.rand(3, 5, 4) >>> b = np.random.rand(6, 5) >>> out_ein = np.einsum('ijk,lj

Custom Theano Op to do numerical integration

一曲冷凌霜 提交于 2019-12-01 05:50:44
I'm attempting to write a custom Theano Op which numerically integrates a function between two values. The Op is a custom likelihood for PyMC3 which involves the numerical evaluation of some integrals. I can't simply use the @as_op decorator as I need to use HMC to do the MCMC step. Any help would be much appreciated, as this question seems to have come up several times but has never been solved (e.g. https://stackoverflow.com/questions/36853015/using-theano-with-numerical-integration , Theano: implementing an integral function ). Clearly one solution would be to write a numerical integrator

Convert einsum computation to dot product to be used in Theano

放肆的年华 提交于 2019-12-01 04:31:33
问题 I have just recently learned about np.einsum and quickly became addicted to it. But it seems that theano doesn't have an equivalent function so I need to convert my numpy code to theano somehow. How can I write the following computation in theano? IX=np.einsum('ijk,lj->ilk',p1,KX) 回答1: You only need to rearrange your axes to get this to work: >>> import numpy as np >>> a = np.random.rand(3, 4, 5) >>> b = np.random.rand(5, 6) >>> np.allclose(np.einsum('ikj,jl->ikl', a, b), np.dot(a, b)) So

Python玩转人工智能最火框架 TensorFlow应用实践 ☝☝☝

送分小仙女□ 提交于 2019-12-01 04:19:48
Python玩转人工智能最火框架 TensorFlow应用实践 随着 TensorFlow 在研究及产品中的应用日益广泛,很多开发者及研究者都希望能深入学习这一深度学习框架。而在昨天机器之心发起的框架投票中,2144 位参与者中有 1441 位都在使用 TensorFlow 框架,是所有框架中使用率最高的。但 TensorFlow 这种静态计算图有一定的学习成本,因此也阻挡了很多准备入坑的初学者。本文介绍了学习 TensorFlow 的系列教程,旨在通过简单的理论与实践帮助初学者一步步掌握 TensorFlow 的编程技巧。 这一系列教程分为 6 部分,从为什么选择 TensorFlow 到卷积神经网络的实现,介绍了初学者所需要的技能。机器之心在本文介绍了 PyTorch 和 Caffe 等深度学习框架的优缺点及 TensorFlow 基础,包括静态计算图、张量、TensorBoard 可视化和模型参数的保存等。 为什么选择 TensorFlow? 在本文中,我们将对比当前最流行的深度学习框架(包括 Caffe、Theano、PyTorch、TensorFlow 和 Keras),帮助你为应用选择最合适的框架。 1. Caffe :第一个主流产品级深度学习库,于 2014 年由 UC Berkeley 启动。 优点: 快速 支持 GPU 漂亮的 Matlab 和 Python 接口

Custom Theano Op to do numerical integration

一个人想着一个人 提交于 2019-12-01 04:09:53
问题 I'm attempting to write a custom Theano Op which numerically integrates a function between two values. The Op is a custom likelihood for PyMC3 which involves the numerical evaluation of some integrals. I can't simply use the @as_op decorator as I need to use HMC to do the MCMC step. Any help would be much appreciated, as this question seems to have come up several times but has never been solved (e.g. https://stackoverflow.com/questions/36853015/using-theano-with-numerical-integration, Theano

Customize Keras' loss function in a way that the y_true will depend on y_pred

谁都会走 提交于 2019-12-01 03:59:58
I'm working on a multi-label classifier. I have many output labels [1, 0, 0, 1...] where 1 indicates that the input belongs to that label and 0 means otherwise. In my case the loss function that I use is based on MSE. I want to change the loss function in a way that when the output label is -1 than it will change to the predicted probability of this label. Check the attached images to best understand what I mean: The scenario is - when the output label is -1 I want the MSE to be equal to zero: This is the scenario: And in such case I want it to change to: In such case the MSE of the second

How to run several Keras neural networks in parallel

萝らか妹 提交于 2019-12-01 03:58:26
I'm trying to use Keras to run a reinforcement learning algorithm. In this algorithm, I'm training a neural network. What's different from other learning problems is that I need to use the neural network itself to generate training data, and repeat this after it updates. I run into problem when I'm trying to generate training data in parallel. The problem is that I can't tell Theano to use GPU while training because it will also use GPU when generating training data and cause problems if invoked by multiple processes. What's more, I Theano wont run in multi-thread mode even when I write THEANO

How to plot a chart in the terminal?

有些话、适合烂在心里 提交于 2019-12-01 03:54:03
问题 I'm researching ML/Theano, and recently came across this script: https://gist.github.com/notmatthancock/68d52af2e8cde7fbff1c9225b2790a7f which was cool to play with. And like all ML researchers, I recently upgraded to a server, and while it's more powerful, it also presented me with a problem. The script is very long, but it ends with this code: def plot_stuff(inputs, outputs, losses, net_func, n_hidden): fig,axes = plt.subplots(1,2,figsize=(12,6)) axes[0].plot(np.arange(losses.shape[0])+1,

Error importing theano “cannot import name gof”

萝らか妹 提交于 2019-12-01 03:35:07
I am current getting the error ImportError: cannot import name gof when importing theano. >>> import theano Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> import theano File "C:\Python27\lib\site-packages\theano\__init__.py", line 63, in <module> from theano.compile import ( File "C:\Python27\lib\site-packages\theano\compile\__init__.py", line 9, in <module> from theano.compile.function_module import * File "C:\Python27\lib\site-packages\theano\compile\function_module.py", line 16, in <module> from theano import gof ImportError: cannot import name gof I am using

getting “pygpu was configured but could not be imported” error while trying with OpenCL+Theano on AMD Radeon

时光毁灭记忆、已成空白 提交于 2019-12-01 03:32:32
I have followed the instructions from this: https://gist.github.com/jarutis/ff28bca8cfb9ce0c8b1a But then when I tried : THEANO_FLAGS=device=opencl0:0 python test.py on the test file I am getting error: ERROR (theano.sandbox.gpuarray): pygpu was configured but could not be imported Traceback (most recent call last): File "/home/mesayantan/.local/lib/python2.7/site-packages/theano/sandbox/gpuarray/ init .py", line 20, in import pygpu File "/usr/src/gtest/clBLAS/build/libgpuarray/pygpu/ init .py", line 7, in from . import gpuarray, elemwise, reduction File "/usr/src/gtest/clBLAS/build