Hallo zusammen,
ich möchte von Python 2 zu Python 3 wechseln und muss dazu ein paar Anpassungen für meinen Theano Code machen.
An einer Stelle bleibe ich dabei hängen.
Folgendes ist mein Code:
[codebox=python file=Unbenannt.txt]import sys; sys.path.insert(0, "../Theano"); sys.path.insert(0, "../../Theano")
import theano; import theano.tensor as T; import theano.sandbox.linalg as sT
from theano import function, printing
import numpy as np
import _pickle as cPickle
print('Theano version: ' + theano.__version__ + ', base compile dir: ' + theano.config.base_compiledir)
theano.config.mode = 'FAST_RUN'
theano.config.optimizer = 'fast_run'
#theano.config.exception_verbosity = 'high'
theano.config.reoptimize_unpickled_function = False
class DEEPvSSGP:
def __init__(self, use_exact_A = False):
X, hyp, MU_S, SIGMA_S, MU, SIGMA, MU_A, SIGMA_A, U, b = T.dmatrices('X', 'hyp', 'MU_S', 'SIGMA_S', 'MU', 'SIGMA', 'MU_A', 'SIGMA_A', 'U', 'b')
y = T.dvector('y')
sn = T.dvector('sn')
sf = T.dvector('sf')
D = np.array([20,20,10])
D_sum = np.array([0,20,40,50])
layers = 2
order = 10
N = 1990
M = 125
LL, KL = self.get_model(lengthscale, lengthscale_p, sn, sf, MU_S, SIGMA_S_trf, MU, SIGMA_trf, MU_A, SIGMA_A, U, b, X, y, D, D_sum, layers, order, N, M)
print('Compiling model...')
inputs = {'X': X, 'MU_A': MU_A, 'SIGMA_A': SIGMA_A, 'MU': MU, 'SIGMA': SIGMA, 'MU_S': MU_S, 'SIGMA_S': SIGMA_S, 'U': U, 'b': b, 'hyp': hyp, 'y': y, 'sn': sn, 'sf': sf}
z = 0.0 * sum([T.sum(v) for v in inputs.values()]) # solve a bug with derivative wrt inputs not in the graph
f = zip(['LL', 'KL'],[LL, KL])
self.f = {fn: theano.function(inputs.values(), fv+z, name=fn, on_unused_input='ignore') for fn,fv in f}
with open('model_exact_A_SV1.save' if use_exact_A else 'model_SV1.save', 'wb') as file_handle:
print('Saving model...')
sys.setrecursionlimit(5000)
cPickle.dump([self.f], file_handle, protocol=cPickle.HIGHEST_PROTOCOL)
def get_model(...):
...
[/code]
Ich habe das Ende mit ... abgekürzt, da ich denke, das es nicht relevant ist, denn ich erhalte diesen Fehler:
[codebox=python file=Unbenannt.txt]
File "<ipython-input-3-81d591fed1b4>", line 71, in <module>
DEEPvSSGP_opt1 = DEEPvSSGP_opt(Q, D, N, M, inputs, opt_params, fixed_params, use_exact_A = True, parallel = False, batch_size = None, print_interval=1)
File "C:\Users\flo9fe\Desktop\DEEPvSSGPCopy\DEEPvSSGP_opt_SV1.py", line 14, in __init__
self.deepvssgp, self.N, self.Q, self.M, self.fixed_params = DEEPvSSGP(use_exact_A), N, Q, M, fixed_params
File "C:\Users\flo9fe\Desktop\DEEPvSSGPCopy\DEEPvSSGP_model_SV1.py", line 34, in __init__
self.f = {fn: theano.function([inputs.values(),z, fv+z], name=fn, on_unused_input='ignore') for fn,fv in f}
File "C:\Users\flo9fe\Desktop\DEEPvSSGPCopy\DEEPvSSGP_model_SV1.py", line 34, in <dictcomp>
self.f = {fn: theano.function([inputs.values(),z, fv+z], name=fn, on_unused_input='ignore') for fn,fv in f}
File "C:\ProgramData\Anaconda3\lib\site-packages\theano\compile\function.py", line 284, in function
raise Exception("Input variables of a Theano function should be "
Exception: Input variables of a Theano function should be contained in a list, even when there is a single input.[/code]
Was ist in Zeile 34 nicht richtig? Mit Python 2.7 funktioniert dieser Code.
Vielleicht noch der Grund warum ich wechseln möchte.
Ich kann ab einer bestimmten Größe der Theanofunktion cPickle nicht mehr richtig verwenden:
Siehe hierzu https://groups.google.com/forum/#!topic ... 8C33U4skXI