Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return type of tf.oneHot depends on backend #435

Closed
bileschi opened this issue Jun 15, 2018 · 1 comment · Fixed by tensorflow/tfjs-core#1110
Closed

Return type of tf.oneHot depends on backend #435

bileschi opened this issue Jun 15, 2018 · 1 comment · Fixed by tensorflow/tfjs-core#1110
Labels
comp:core type:bug Something isn't working

Comments

@bileschi
Copy link
Contributor

To get help from the community, check out our Google group.

TensorFlow.js version

0.11.8

Browser version

irrelevant

Describe the problem or feature request

tf.oneHot returns a tensor of dtype 'float32' with some backends, and with dtype 'int32' in other backends.

Code to reproduce the bug / link to feature request

describeWithFlags('oneHotType', ALL_ENVS, () => {
  expectedType = 'int32'
  fit('Output type is what', () => {
    const indices = tf.tensor1d([0, 1], 'int32');
    const res = tf.oneHot(indices, 2);
    console.log("XXXXXXXXXXXXXXXX");
    console.log(res.dtype);
    expect(res.dtype).toEqual(expectedType);
  });
});

outputs

LOG: 'XXXXXXXXXXXXXXXX'
LOG: 'int32'
LOG: 'XXXXXXXXXXXXXXXX'
LOG: 'int32'
LOG: 'XXXXXXXXXXXXXXXX'
LOG: 'float32'
Chrome 67.0.3396 (Linux 0.0.0) oneHot {"BACKEND":"test-cpu"} Output type is int32 FAILED
	Expected 'float32' to equal 'int32'.
	    at <Jasmine>
	    at UserContext.<anonymous> (src/ops/array_ops_test.ts:2171:22 <- src/ops/array_ops_test.js:7084:39)
	    at <Jasmine>

@manrajgrover
Copy link
Contributor

@bileschi Looks like CPU backend was using default float32 as dtype. Providing int32 as dtype to output fixes it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:core type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants