It's a tale of two nets, one that works fine and one that suddenly fails 
mysteriously.
Here's the bit that's still working:
#---------------------------------------------


X,Y = sets.mnist32(); idx = np.arange(X.shape[0]);np.random.shuffle(idx)

def plot(x):
    plt.imshow(x.reshape((32,32)),cmap='Greys_r');plt.show()

class Mask(Layer): 
    ''' A layer which applies a nearly-bianarized multiplicative mask, w, 
with a nonzero bias, b, to its input. 
    The absolute values of weights are raised to the power p before 
bounding by the hyperbolic tangent function, 
    and before the addition of bais.'''

    def __init__(self, incoming, b=.01, p=4, initial=.15, **kwargs):
        super(Mask, self).__init__(incoming, **kwargs)
        num_inputs = self.input_shape[1]
        self.b = b;  self.p = p
        W = np.ones((num_inputs,)).astype(floatX)*initial
        W = shared(W)
        self.W = self.add_param(W,(num_inputs,), name = 'W_Mask')

    def get_output_for(self,input,**kwargs):
        return((tanh((abs(self.W)**self.p) )+self.b)*input)

# Large Net.

x = T.matrix('x')
In =  InputLayer((None,X.shape[1]),input_var=x) 
Noise = GaussianNoiseLayer(In)
Layer_1 =  DenseLayer(Noise,num_units=(X.shape[1]),nonlinearity=tanh) 
LM =  Mask(Layer_1)
Layer_2 =  DenseLayer(LM,num_units=X.shape[1],nonlinearity=sigmoid)
Out = get_output(Layer_2)

params = get_all_params(Layer_2)
cost = ((x-Out)**2).sum()+ \
       .001* (regularize_layer_params(LM,l1))+ \
       .01* (regularize_layer_params(Layer_2,l2))+ 
(regularize_layer_params(Layer_1,l2))

Updates = sgd(cost,params,learning_rate=.001)

train  = function([x],[cost, Out], updates=Updates)

import tqdm
bar = tqdm.tqdm
batchsize = 500
batches = len(idx) // batchsize
epochs = 10

E = []

while epochs:
    np.random.shuffle(idx)
    for b in bar(range(batches)):
        XX = X[idx[b*batchsize:(b+1)*batchsize]]
        E.append(train(XX)[0])

#And here's where things go off the rails:
#---------------------------------------------------------------------------

#Extract small net

before = [Layer_1.W.get_value(),Layer_1.b.get_value()]
after  = Layer_2.W.get_value()

m      = LM.W.get_value()
active = []

for i,n in enumerate(range(len(m))):
    if m[n] > .5:
        active.append(i)
        
before = [before[0][:,active],before[1][active]]
after = after[active,:]

x = T.matrix('x')

In_2 =  InputLayer((None,X.shape[1]), inpput_var=x) 
Noise2 = GaussianNoiseLayer(In_2)
Layer_1_2 =  DenseLayer(Noise2,num_units=171,nonlinearity=tanh)
Layer_1_2.W.set_value(before[0])
Layer_1_2.b.set_value(before[1])
Layer_2_2 =  DenseLayer(Layer_1_2,num_units=1024,nonlinearity=sigmoid)
Layer_2_2.W.set_value(after)
#Layer_22.b.set_value(after[1])
Out_2 = get_output(Layer_2_2)

params_2 = get_all_params(Layer_2_2)

cost_2 = ((x-Out_2)**2).sum()+.01* (regularize_layer_params(Layer_2_2,l2))+ 
(regularize_layer_params(Layer_1_2,l2))

Updates_2 = sgd(cost_2,params_2,learning_rate=.001)

train_2  = function([x],[cost_2, Out_2], updates=Updates_2)

plot(X[0]);plt.show()
#plot(Out2.eval({x2:XX[:1]}));plt.show()

#And the error:
#------------------------------------------------------------------------------------------

---------------------------------------------------------------------------MissingInputError
                         Traceback (most recent call 
last)<ipython-input-7-2d5d42706ca7> in <module>()     32 Updates_2 = 
sgd(cost_2,params_2,learning_rate=.001)     33 ---> 34 train_2  = 
function([x],[cost_2, Out_2], updates=Updates_2)     35      36 
plot(X[0]);plt.show()
/usr/local/lib/python3.4/dist-packages/theano/compile/function.py in 
function(inputs, outputs, mode, updates, givens, no_default_updates, 
accept_inplace, name, rebuild_strict, allow_input_downcast, profile, 
on_unused_input)    320                    on_unused_input=on_unused_input,    
321                    profile=profile,--> 322                    
output_keys=output_keys)    323     # We need to add the flag check_aliased 
inputs if we have any mutable or    324     # borrowed used defined inputs
/usr/local/lib/python3.4/dist-packages/theano/compile/pfunc.py in pfunc(params, 
outputs, mode, updates, givens, no_default_updates, accept_inplace, name, 
rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)    
478                          accept_inplace=accept_inplace, name=name,    479   
                       profile=profile, on_unused_input=on_unused_input,--> 480 
                         output_keys=output_keys)    481     482 
/usr/local/lib/python3.4/dist-packages/theano/compile/function_module.py in 
orig_function(inputs, outputs, mode, accept_inplace, name, profile, 
on_unused_input, output_keys)   1781                    profile=profile,   1782 
                   on_unused_input=on_unused_input,-> 1783                    
output_keys=output_keys).create(   1784             defaults)   1785 
/usr/local/lib/python3.4/dist-packages/theano/compile/function_module.py in 
__init__(self, inputs, outputs, mode, accept_inplace, function_builder, 
profile, on_unused_input, fgraph, output_keys)   1433             # OUTPUT 
VARIABLES)   1434             fgraph, additional_outputs = std_fgraph(inputs, 
outputs,-> 1435                                                     
accept_inplace)   1436             fgraph.profile = profile   1437         else:
/usr/local/lib/python3.4/dist-packages/theano/compile/function_module.py in 
std_fgraph(input_specs, output_specs, accept_inplace)    174     175     fgraph 
= gof.fg.FunctionGraph(orig_inputs, orig_outputs,--> 176                        
           update_mapping=update_mapping)    177     178     for node in 
fgraph.apply_nodes:
/usr/local/lib/python3.4/dist-packages/theano/gof/fg.py in __init__(self, 
inputs, outputs, features, clone, update_mapping)    179     180         for 
output in outputs:--> 181             self.__import_r__(output, reason="init")  
  182         for i, output in enumerate(outputs):    183             
output.clients.append(('output', i))
/usr/local/lib/python3.4/dist-packages/theano/gof/fg.py in __import_r__(self, 
variable, reason)    374         # Imports the owners of the variables    375   
      if variable.owner and variable.owner not in self.apply_nodes:--> 376      
           self.__import__(variable.owner, reason=reason)    377         if 
(variable.owner is None and    378                 not isinstance(variable, 
graph.Constant) and
/usr/local/lib/python3.4/dist-packages/theano/gof/fg.py in __import__(self, 
apply_node, check, reason)    416                             "for more 
information on this error."    417                             % str(node)),--> 
418                             variable=r)    419     420         for node in 
new_nodes:
MissingInputError: An input of the graph, used to compute Shape(input), was not 
provided and not given a value.Use the Theano flag 
exception_verbosity='high',for more information on this error.

Backtrace when the variable is created:
  File "/usr/local/lib/python3.4/dist-packages/ipykernel/kernelbase.py", line 
228, in dispatch_shell
    handler(stream, idents, msg)
  File "/usr/local/lib/python3.4/dist-packages/ipykernel/kernelbase.py", line 
391, in execute_request
    user_expressions, allow_stdin)
  File "/usr/local/lib/python3.4/dist-packages/ipykernel/ipkernel.py", line 
199, in do_execute
    shell.run_cell(code, store_history=store_history, silent=silent)
  File 
"/usr/local/lib/python3.4/dist-packages/IPython/core/interactiveshell.py", line 
2705, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File 
"/usr/local/lib/python3.4/dist-packages/IPython/core/interactiveshell.py", line 
2809, in run_ast_nodes
    if self.run_code(code, result):
  File 
"/usr/local/lib/python3.4/dist-packages/IPython/core/interactiveshell.py", line 
2869, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-7-2d5d42706ca7>", line 18, in <module>
    In_2 =  InputLayer((None,X.shape[1]), inpput_var=x)
  File "/usr/local/lib/python3.4/dist-packages/lasagne/layers/input.py", line 
63, in __init__
    input_var = input_var_type(var_name)


-- 

--- 
You received this message because you are subscribed to the Google Groups 
"theano-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to