tristandeleu / ntm-one-shot

One-shot Learning with Memory-Augmented Neural Networks
MIT License
421 stars 94 forks source link

Using new data #11

Closed nargesam closed 7 years ago

nargesam commented 7 years ago

Hi,

I created a sample function in generator.py to pass a random valued array like this:

def sample(self, nb_samples): example_inputs = np.random.rand(16, 50, 20 * 20) example_outputs = np.random.randint(5, size=(16, 50)).astype('int32') return example_inputs, example_outputs

When I run the model it gives me an error: IndexError: index 10 is out of bounds for axis 1 with size 10 Apply node that caused the error: AdvancedIncSubtensor{inplace=False, set_instead_of_inc=False}(<TensorType(float64, matrix)>, <TensorType(bool, vector)>, TensorConstant{[ 0 1 2 .. 13 14 15]}, AdvancedSubtensor.0)

You can see the complete output bellow. I cannot understand what goes wrong. It is the same shape as the main data just random values. Could you please tell me what I am doing wrong?

Thanks.

`Compiling the model... Done Training... Traceback (most recent call last): File "omniglot.py", line 83, in omniglot() File "omniglot.py", line 69, in omniglot acc = accuracy_fn(example_input, example_output) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/venv/lib/python2.7/site-packages/theano/compile/function_module.py", line 898, in call storage_map=getattr(self.fn, 'storage_map', None)) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/venv/lib/python2.7/site-packages/theano/gof/link.py", line 325, in raise_with_op reraise(exc_type, exc_value, exc_trace) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/venv/lib/python2.7/site-packages/theano/compile/function_module.py", line 884, in call self.fn() if output_subset is None else\ File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/venv/lib/python2.7/site-packages/theano/scan_module/scan_op.py", line 989, in rval r = p(n, [x[0] for x in i], o) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/venv/lib/python2.7/site-packages/theano/scan_module/scan_op.py", line 978, in p self, node) File "theano/scan_module/scan_perform.pyx", line 405, in theano.scan_module.scan_perform.perform (/Users/narges/.theano/compiledir_Darwin-16.6.0-x86_64-i386-64bit-i386-2.7.10-64/scan_perform/mod.cpp:4606) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/venv/lib/python2.7/site-packages/theano/gof/link.py", line 325, in raise_with_op reraise(exc_type, exc_value, exc_trace) File "theano/scan_module/scan_perform.pyx", line 397, in theano.scan_module.scan_perform.perform (/Users/narges/.theano/compiledir_Darwin-16.6.0-x86_64-i386-64bit-i386-2.7.10-64/scan_perform/mod.cpp:4490) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/venv/lib/python2.7/site-packages/theano/gof/op.py", line 872, in rval r = p(n, [x[0] for x in i], o) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/venv/lib/python2.7/site-packages/theano/tensor/subtensor.py", line 2244, in perform inplace_increment(out[0], tuple(inputs[2:]), inputs[1]) IndexError: index 10 is out of bounds for axis 1 with size 10 Apply node that caused the error: AdvancedIncSubtensor{inplace=False, set_instead_of_inc=False}(<TensorType(float64, matrix)>, <TensorType(bool, vector)>, TensorConstant{[ 0 1 2 .. 13 14 15]}, AdvancedSubtensor.0) Toposort index: 2 Inputs types: [TensorType(float64, matrix), TensorType(bool, vector), TensorType(int64, vector), TensorType(int32, vector)] Inputs shapes: [(16, 10), (16,), (16,), (16,)] Inputs strides: [(80, 8), (50,), (8,), (4,)] Inputs values: ['not shown', 'not shown', 'not shown', 'not shown'] Outputs clients: [['output']]

Backtrace when the node is created(use Theano flag traceback.limit=N to make it longer): File "omniglot.py", line 83, in omniglot() File "omniglot.py", line 47, in omniglot accuracies = accuracy_instance(T.argmax(output_var, axis=2), target_var, batch_size=generator.batch_size) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/examples/mann/utils/metrics.py", line 28, in accuracy_instance targets.dimshuffle(1, 0)], outputs_info=[accuracy_0, indices_0]) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/venv/lib/python2.7/site-packages/theano/scan_module/scan_views.py", line 158, in foldl name=name) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/venv/lib/python2.7/site-packages/theano/scan_module/scan_views.py", line 115, in reduce name=name) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/venv/lib/python2.7/site-packages/theano/scan_module/scan.py", line 773, in scan condition, outputs, updates = scan_utils.get_updates_andoutputs(fn(*args)) File "/Users/narges/Dropbox/OneShotLearningPaper/ntm-one-shot-master/examples/mann/utils/metrics.py", line 22, in step acc = T.inc_subtensor(acc[batch_range, idx[batch_range, t]], T.eq(p, t))

HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node. Apply node that caused the error: forall_inplace,cpu,scan_fn}(Elemwise{Maximum}[(0, 0)].0, Elemwise{eq,no_inplace}.0, Subtensor{int64:int64:int8}.0, IncSubtensor{InplaceSet;:int64:}.0, IncSubtensor{InplaceSet;:int64:}.0) Toposort index: 159 Inputs types: [TensorType(int64, scalar), TensorType(bool, matrix), TensorType(int32, matrix), TensorType(float64, 3D), TensorType(int32, (True, False, False))] Inputs shapes: [(), (50, 16), (50, 16), (2, 16, 10), (1, 16, 5)] Inputs strides: [(), (1, 50), (4, 200), (1280, 80, 8), (320, 20, 4)] Inputs values: [array(50), 'not shown', 'not shown', 'not shown', 'not shown'] Outputs clients: [[Subtensor{int64}(forall_inplace,cpu,scan_fn}.0, ScalarFromTensor.0)], []]

HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag 'optimizer=fast_compile'. If that does not work, Theano optimizations can be disabled with 'optimizer=None'. HINT: Use the Theano flag 'exception_verbosity=high' for a debugprint and storage map footprint of this apply node.`

tristandeleu commented 7 years ago

Hello! This error is due to an imbalance in your targets example_outputs. For the omniglot example, each episode has an equal number of samples per class (called nb_samples_per_class in the generator), which is not the case here if you define your example_outputs as random labels. The function computing the accuracy expects an equal number of samples per classes.

To make it work in a random setup, you could do something like

def sample(self, nb_samples):
    example_inputs = np.random.rand(16, 50, 20 * 20)
    example_outputs = np.zeros((16, 50), dtype='int32')
    for i in range(16):
        example_outputs[i] = np.random.permutation(range(5) * 10)

    return example_inputs, example_outputs
nargesam commented 7 years ago

Thank you!