Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

python regression metrics not working #1163

@jmschrei

Description

@jmschrei

I have a network which looks like this:

sequence = mx.symbol.Variable( name='data' )

ip1 = InnerProduct( sequence, 250, name="ip1" )
ip2 = InnerProduct( ip1, 100, name="ip2" )
ip3 = InnerProduct( ip2, 50, name="ip3" )
ip4 = mx.symbol.FullyConnected( data=ip3, num_hidden=1, name="y" )
y = mx.symbol.LinearRegressionOutput( data=ip4, name="y" )

train_data  = mx.io.NDArrayIter( X_train, label={ 'y_label' : y_train }, batch_size=batch_size )
eval_data   = mx.io.NDArrayIter( X_test,  label={ 'y_label' : y_test }, batch_size=batch_size )

model = mx.model.FeedForward( ctx=[ mx.gpu(0), mx.gpu(1), mx.gpu(2), mx.gpu(3) ], 
                                 symbol=y,
                                 num_epoch=15,
                                 learning_rate=0.0001,
                                 wd=0.1,
                                 optimizer='adam',
                           )
model.fit( X=train_data,
           eval_data=eval_data,
           eval_metric=mx.metric.RMSE(),
           batch_end_callback=mx.callback.Speedometer(batch_size)
     )

If I feed in y_train and y_test as an array, like I do with classification problems, I get the following error:

Traceback (most recent call last):
  File "ananas.py", line 84, in <module>
    main()
  File "ananas.py", line 73, in main
    batch_end_callback=mx.callback.Speedometer(batch_size)
  File "/net/noble/vol1/home/jmschr/anaconda/lib/python2.7/site-packages/mxnet-0.5.0-py2.7.egg/mxnet/model.py", line 655, in fit
    logger=logger, work_load_list=work_load_list, monitor=monitor)
  File "/net/noble/vol1/home/jmschr/anaconda/lib/python2.7/site-packages/mxnet-0.5.0-py2.7.egg/mxnet/model.py", line 241, in _train_multi_device
    eval_metric.update(data_batch.label, executor_manager.cpu_output_arrays)
  File "/net/noble/vol1/home/jmschr/anaconda/lib/python2.7/site-packages/mxnet-0.5.0-py2.7.egg/mxnet/metric.py", line 84, in update
    assert label.shape == pred.shape
AssertionError

When I check the shapes, they are(256,) and (256,1) when my batch_size is 256. If I reshape my y's to be matrices with 1 column ( y_train = y_train.reshape( y_train.shape[0], 1 ) ), I get the following error:

INFO:root:Auto-select kvstore type = local_update_cpu
INFO:root:Start training with [gpu(0), gpu(1), gpu(2), gpu(3)]
[10:58:18] ./dmlc-core/include/dmlc/logging.h:208: [10:58:18] src/ndarray/ndarray.cc:159: Check failed: from.shape() == to->shape() operands shape mismatch
Traceback (most recent call last):
  File "ananas.py", line 86, in <module>
    main()
  File "ananas.py", line 75, in main
    batch_end_callback=mx.callback.Speedometer(batch_size)
  File "/net/noble/vol1/home/jmschr/anaconda/lib/python2.7/site-packages/mxnet-0.5.0-py2.7.egg/mxnet/model.py", line 655, in fit
    logger=logger, work_load_list=work_load_list, monitor=monitor)
  File "/net/noble/vol1/home/jmschr/anaconda/lib/python2.7/site-packages/mxnet-0.5.0-py2.7.egg/mxnet/model.py", line 218, in _train_multi_device
    executor_manager.load_data_batch(data_batch)
  File "/net/noble/vol1/home/jmschr/anaconda/lib/python2.7/site-packages/mxnet-0.5.0-py2.7.egg/mxnet/executor.py", line 417, in load_data_batch
    _load_label(data_batch, self.label_arrays)
  File "/net/noble/vol1/home/jmschr/anaconda/lib/python2.7/site-packages/mxnet-0.5.0-py2.7.egg/mxnet/executor.py", line 301, in _load_label
    _load_general(batch.label, targets)
  File "/net/noble/vol1/home/jmschr/anaconda/lib/python2.7/site-packages/mxnet-0.5.0-py2.7.egg/mxnet/executor.py", line 293, in _load_general
    d_src[slice_idx].copyto(d_dst)
  File "/net/noble/vol1/home/jmschr/anaconda/lib/python2.7/site-packages/mxnet-0.5.0-py2.7.egg/mxnet/ndarray.py", line 361, in copyto
    return NDArray._copyto(self, out=other)
  File "/net/noble/vol1/home/jmschr/anaconda/lib/python2.7/site-packages/mxnet-0.5.0-py2.7.egg/mxnet/ndarray.py", line 654, in unary_ndarray_function
    c_array(NDArrayHandle, (out.handle,))))
  File "/net/noble/vol1/home/jmschr/anaconda/lib/python2.7/site-packages/mxnet-0.5.0-py2.7.egg/mxnet/base.py", line 76, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: [10:58:18] src/ndarray/ndarray.cc:159: Check failed: from.shape() == to->shape() operands shape mismatch

How do I run regression?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions