Morgan Funtowicz
Morgan Funtowicz

Reputation: 85

CNTK Python - one_hot encoding no prototype

I'm trying to use the cntk.utils.one_hot as follow :

# actions is numpy array of shape (32, 1) and _output_shape is 6
actions = one_hot(actions, self._output_shape)

But it complains that class numpy.float32 is not supported.

I've tried to convert to Python list:

actions = one_hot(list(actions), self._output_shape)

I'm getting the following error :

  File "/home/malmo_user/Workspace/malmo-collab/msrc-rl/model/backend/cntk.py", line 213, in train
    actions = one_hot(list(actions), self._output_shape)
  File "/home/malmo_user/anaconda3/envs/cntk-py34/lib/python3.4/site-packages/cntk/utils/swig_helper.py", line 58, in wrapper
    result = f(*args, **kwds)
  File "/home/malmo_user/anaconda3/envs/cntk-py34/lib/python3.4/site-packages/cntk/utils/__init__.py", line 76, in one_hot
    value = cntk_py.Value.create_one_hot_float(num_classes, batch, device, False)
NotImplementedError: Wrong number or type of arguments for overloaded function 'Value_create_one_hot_float'.
  Possible C/C++ prototypes are:
    CNTK::Value::CreateOneHotFloat(size_t,std::vector< std::vector< size_t,std::allocator< size_t > >,std::allocator< std::vector< size_t,std::allocator< size_t > > > > const &,CNTK::DeviceDescriptor const &,bool)
    CNTK::Value::CNTK_Value_CreateOneHotFloat__SWIG_0(size_t,std::vector< std::vector< size_t,std::allocator< size_t > >,std::allocator< std::vector< size_t,std::allocator< size_t > > > > const &,CNTK::DeviceDescriptor const &)

Upvotes: 3

Views: 145

Answers (1)

Sayan Pathak
Sayan Pathak

Reputation: 870

The input to one_hot are indices. They must be integers. Try

actions.astype(int).tolist()

Upvotes: 1

Related Questions