# Questions tagged [theano]

1170 questions

3

votes

0

answer

20

Views

### Computational graph vs (computer algebra) symbolic expression

I was reading Baydin et al, Automatic Differentiation in Machine Learning: a Survey, 2018 (Arxiv), which differentiates between symbolic differentiation and automatic differentiation (AD). It then says:
AD Is Not Symbolic Differentiation.
Symbolic differentiation is the automatic manipulation of [sy...

1

votes

1

answer

716

Views

### model.fit() generates ERROR: ValueError: All input arrays (x) should have the same number of samples

I have a keras model with several custom layers. When I run:
model_.compile(optimizer=rms, loss=contrastive_loss,metrics=['accuracy'])
It compiles without any problems.
But when I try to fit the model with a list of arrays:
X = [T1,R1] + [T2, R2]
model_.fit(X, [None]*2, epochs=50, batch_size=32)
I...

1

votes

0

answer

247

Views

### Keras- Binarizing Weights Prior to Forward and Backwards Propogation

I am trying to replicate the binarization process used in https://github.com/MatthieuCourbariaux/BinaryConnect on a DNN constructed in Keras, where prior to determining the weight gradients they are binarized stochasticly using the following two functions:
# hard_sigmoid(); Clips the input, x, to [0...

1

votes

0

answer

131

Views

### a TypeError in fit function when using keras with theano backend

my theano version is 1.0.1+unknown.
my keras version is 2.1.3
i'm implementing stacked LSTM autoencoder in keras and this is my code:
timesteps = x_train.shape[1]
input_dim = 1
inputs = Input(batch_shape=(1,timesteps, input_dim))
encoded = LSTM(7,return_sequences = True)(inputs)
encoded = LSTM(5,ret...

1

votes

1

answer

64

Views

### How is Theano based ElemwiseSumLayer of Lasagne converted in Keras

I have a Net built in Theano. I am trying to convert it to Keras.
net['voxres2_out'] = ElemwiseSumLayer([net['conv1c'], net['voxres2_conv2']])
Now, I want a conversion of this statement in Theano to Keras. However, I am unsure about which layer would be a substitute of the same functionality in Kera...

1

votes

0

answer

99

Views

### pymc3 model with ODE solver using theano

I am using a model where the mean response depends on the solution to an ODE. I am trying to fit this model using pymc3, but am running into problems (relating to missing test values) when joining the ODE solver to the model.
Model
y_t is Lognormally distributed with mean mu_t and standard deviation...

1

votes

1

answer

107

Views

### problems installing Theano with Anaconda3 (Python version 3.6)

I have tried to install theano as indicated in the instruction
typing pip install theano on the Anaconda prompt
I have encountered the following issue.
It gave me these errors:
(base) C:\Users >pip install theano
Collecting theano
Exception:
Traceback (most recent call last):
File 'C:\Users\Anacond...

1

votes

0

answer

636

Views

### AttributeError: 'Conv2D' object has no attribute 'subsample'

i am trying to run the python repository for digit classification using Mnist dataset in nengo but unable to get the results due to this error 'AttributeError: 'Conv2D' object has no attribute 'subsample' i tried hard to get rid of this error but failed any one who can suggest me the solution to thi...

1

votes

0

answer

106

Views

### How do I set the keras backend in python dynamically when loaded using supervisor

How do I set the keras backend in python dynamically when loaded using supervisor?. When I load the python file using supervisor, the environmental variables seem to override the backend setup in the below code.
from keras import backend as K
import os
os.environ['KERAS_BACKEND'] = 'theano'
reload(...

1

votes

0

answer

20

Views

### Implemented LSTM inference code shows different test loss compared to using lasagne.

I have difficulty implementing LSTM inference code using matlab. I extraced weight from trained model using theano and lasagne. And then, i coded LSTM inference(test) code using extraced weights and biases.
The loss of implemented inference code shows about 5, but the test loss of theano and lasagn...

1

votes

0

answer

76

Views

### Theano/PyMC3 Dot Product Error (Potential DGEMM failure)

I am attempting to use theano with pymc3 to make a model as shown
from scipy import stats
N = 100
height = stats.norm.rvs(size=N, loc=10, scale=2)
leg_prop = stats.uniform.rvs(size=N, loc=0.4, scale=0.5)
leg_left = leg_prop * height + stats.norm.rvs(size=N, loc=0, scale=0.02)
leg_right = leg_prop *...

1

votes

0

answer

110

Views

### Importing theano with GPU device on Windows conda

I'm having some troubles working with a workstation with Conda for Windows. I'm not too familiar with the OS and this is the first time I try GPU support for theano there, to no avail.
The thing is, when I use an Anaconda bash, I can put this:
set 'MKL_THREADING_LAYER=GNU'
set THEANO_FLAGS=device=cu...

1

votes

0

answer

350

Views

### How to set batch_size, steps per epoch and validation steps

I am writing cnn using Keras with theano backend. I dont understand how to set values for batch_size, steps_per_epoch and validation_steps. If i have 240,000 images in the training set and 60,000 images in the test set, what must be the value of batch_size, steps_per_epoch and validation_steps?

1

votes

0

answer

95

Views

### Overriding existing lock by dead process '12224' (I am process '2516')

Using Theano backend.
(57720L, 51L) (57720L, 5L) (850L, 51L) (850L,)
WARNING (theano.gof.compilelock): Overriding existing lock by dead process '12224' (I am process '2516')
what is the meaning of that, and how to deal with it.

1

votes

1

answer

61

Views

### Switch between keras backend in same program

Is it possible to switch between keras backend in same python program in which both backend specific functions are imported from the keras internal (tensorflow_backend.py, theano_backend.py and cntk_backend.py).
When I set os.environ[KERAS_BACKEND]='theano' I get errors from Keras tensorflow interna...

1

votes

0

answer

128

Views

### How to calculate the max value for n_jobs?

Is there a way to calculate the max value for n_jobs given that my system CPU properties are known?
Here is the computation being performed:
classifier = KerasClassifier(build_fn=buildANN, batch_size=10, epochs=100)
accuracy = cross_val_score(estimator=classifier, X=X_train, y=y_train, cv=10, n_jo...

1

votes

1

answer

75

Views

### Input Format for Mulivariate Time Series Binary Classification

I am trying to use an LSTM model for binary classification on multivariate time series data. I have seven properties collected over the course of the day for about 100 days (i.e. 100 arrays of size [9000, 7]). Each of these arrays has a single classification status of either 1 or 0.
I've started ou...

1

votes

0

answer

104

Views

### theano import error in linux using python3.6 when using cpu as config device

I have installed theano with python3.6 using pip install theano and Getting below error while importing theano even though I configured theano to run with cpu.
/usr/bin/ld: /usr/local/lib/libpython3.6m.a(abstract.o): relocation R_X86_64_32S against `_Py_NotImplementedStruct' can not be used when mak...

1

votes

0

answer

609

Views

### Can not import Theano

I have cloned theano from the github and installed it via python setup.py install but I've got the following error when trying to import it:
import theano.tensor as T
Problem occurred during compilation with the command line below:
'C:\MinGW\bin\g++.exe' -shared -g -DNPY_NO_DEPRECATED_API=NPY_1_7_AP...

1

votes

0

answer

165

Views

### PYMC3: How to use math.switch for high dimensional random variables

I am currently trying to implement change point detection using this guide: http://nbviewer.jupyter.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter1_Introduction/Ch1_Introduction_PyMC3.ipynb
It uses a switch statement to decide between the p...

1

votes

0

answer

56

Views

### How to solve a linear system with cholesky decomposition with sparse matrix in Python?

I have a sparse matrix and i performed Cholesky decomposition with Theano with this line:
theano.tensor.slinalg.Cholesky(lower=True)
where it said it worked and showed this:
Cholesky{lower=, destructive=False, on_error='raise'}
How should i solve the system and find x? I tried with theano.tensor.sl...

1

votes

0

answer

288

Views

### AttributeError: Can't pickle local object 'Op.make_py_thunk.<locals>.rval while running Pymc code

I am new to PyMC3. While learning PyMC3, I re-created a sample program from a blog (which presumably ran for the author), and run into the following error: AttributeError: Can't pickle local object 'Op.make_py_thunk..rval'. I am completely stuck and any guidance will be appreciated. Relevant code fo...

1

votes

0

answer

20

Views

### Python Theano tensor @as_op - use a dictionary as itypes?

I'm doing Bayesian analysis using PyMC3 package and use Theano. If I wanted to use two parameters, I was able to do,
@as_op(itypes=[theano.tensor.dscalar, theano.tensor.dscalar], otypes=[theano.tensor.dvector])
Now my input is a dictionary containing the names and values. What should be my itypes. P...

1

votes

1

answer

26

Views

### How to implement Theano.tensor.Lop in tensorflow?

Recently, I want to rewrite some Theano coding in tensorflow. However, I encountered the problem that I do not know how to write Lop operator in tensorflow. The following picture is the API about Theano.tensor.Lop.
The following is the initial coding in Theano.
def svgd_gradient(X0):
hidden, _, mse...

1

votes

0

answer

293

Views

### theano gpu not working on the google colab

I'm trying to run a theano code on the gpu using google colab but it doesn't work. Here is my code which is picked up from the Tutorial and expected to print out Used the gpu while it is out put is Used the cpu. I used this Stack overflow question to configure gpu in run time mode. Here is my code a...

1

votes

0

answer

36

Views

### How to substract one large vector by another?

I want to calculate the vectored difference between two vectors of great dimension. Both are columns of a dataframe.
I am able to subtract a list of arrays to an array and put it to the power of 2
(train['quest_emb'][0] - train['sent_emb'][0])**2
but not to generalize it with a dataframe column of l...

1

votes

0

answer

106

Views

### Defining a numeric (custom) likelihood function in PyMC3

After looking at several questions/answers (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) and PyMC3's documentation, I've managed to create a MCVE of my MCMC setup (see below).
My fitted parameters are continuous and discrete, so the priors are defined using pm.Uniform and pm.DiscreteUniform (with a re-scaling...

1

votes

0

answer

184

Views

### use a saved trained model to predict on new dataset

I am using theano, sklearn and numpy in Python. I found this code for saving my trained network and predict on my new dataset in this link https://github.com/lzhbrian/RBM-DBN-theano-DL4J/blob/master/src/theano/code/logistic_sgd.py. the part of the code I am using is this :
'''
An example of how to l...

1

votes

0

answer

14

Views

### How theano.function can be the input of another function in python?

I have two .py files. In one of them, I have this function:
def score_semeval2015_term(pred_fn, nnet_outdir, data_dir):
def predict(dataset):
x_test = numpy.load(os.path.join(data_dir, 'semeval_{}_x.npy').format(dataset))
x_test_term = numpy.load(os.path.join(data_dir, 'semeval_{}_x_term.npy').forma...

1

votes

0

answer

164

Views

### How to get rid of theano.gof.compilelock?

I am using the joblib library to run multiple NN on my multiple CPU at once. the idea is that I want to make a final prediction as the average of all the different NN predictions. I use keras and theano on the backend.
My code works if I set n_job=1 but fails for anything >1.
Here is the error messa...

1

votes

0

answer

271

Views

### How can I solve theano GPU pygpu error on Google Colab?

I'm using theano gpu on Google Colab and I get this error:
ERROR (theano.gpuarray): pygpu was configured but could not be imported or is too old (version 0.7 or higher required)
I've set:
import os
os.environ['THEANO_FLAGS']='device=cuda, floatX=float32'
And changed the runtime type to hardware acce...

1

votes

0

answer

133

Views

### IOError: [Errno 2] No such file or directory when training Keras model

I have been having some issues with training my sequential model in Keras. I am new to the subject, therefore there is a lot of following tutorials and code snippets involved...
I was building a basic CNN to distinguish between linear infrastructure and geomorphological features on the basis of orth...

1

votes

0

answer

302

Views

### how to update scan Cython code in Theano?

when I use following ways to update ,there is some problem, system told me 'missing header for unified diff at line 1 of patch
cd theano/scan_module/
cython scan_perform.pyx
patch scan_perform.c numpy_api_changes.diff
by the way, the reason I want to update is that when I used theano in windows anac...

1

votes

0

answer

38

Views

### Cannot calculate gradients using theano

I cannot calculate gradient if I use theano.fft.rfft. Below is a minimal code example which reproduce the problem:
import theano.tensor as tt
import theano.tensor.fft
def fft_real(input):
a = input.dimshuffle('x', 0)
spec = tt.fft.rfft(a, norm='ortho')
return spec[0,:,0]
inp = tt.vector('real_n', dt...

1

votes

2

answer

253

Views

### Issue with installing Keras library from Anaconda

I have been trying to install 'Keras' library from Anaconda on my laptop. I have the latest version of Anaconda. After that, I tried
conda update conda
conda update --all
The above two succeeds. After that I tried
conda install -c conda-forge keras
conda install keras
Both of the above fails with...

1

votes

0

answer

9

Views

### Keras2.0 implement by theano backend

I am a new keras learner,i have some question, here is my code:
from keras.layers import Input
img = Input(batch_shape=(10, 3, 32, 32), name='input_img')
print(img.shape)
If I use tensorlow backend , it's print (10, 3, 32, 32).
but if i use theano backend, it's print Shape.0.
Why?

1

votes

0

answer

35

Views

### Setting of backend for keras

I need to change the keras backend from default tensorflow to theano. But my default python version is 3.7, which does not seem to work with keras (the import line crashes). So, I first had to create a specific environment.
After creating a specific python environment with anaconda, as suggested by...

1

votes

0

answer

10

Views

### Issue importing the Theano framework using Python

Can't import theano. When I put this command in my terminal python -c 'import theano; print (theano.__version__)' , this message shows up:
[[email protected]] match_arg (utils/args/args.c:159): unrecognized argument pmi_args
[[email protected]] HYDU_parse_array (utils/args/args.c:174): argument...

1

votes

1

answer

2.3k

Views

### Theano TypeError: function() takes at least 1 argument (1 given)

One of my Theano functions does not take any inputs and only uses shared variables to calculate the output. But this function throws a TypeError: function() takes at least 1 argument (1 given).
Here a minimal example:
import theano as th
import theano.tensor as T
import numpy as np
x, y = T.dscala...

1

votes

1

answer

1.6k

Views

### Theano shared variable update causes `ValueError: length not known`

Minimal example code:
import theano as th
import theano.tensor as T
import numpy as np
x = T.dscalars('x')
z = th.shared(np.zeros(2))
updates = [z, z+x]
f1 = th.function(inputs=[x], updates=updates)
f1(3)
print z.get_value()
Error message:
Traceback (most recent call last):
File '/home/temp2/thean...