How can I convert int32 to float32 in Deeplearn.js?

165 views Asked by At

This code worked for me in December 2017, but with the latest release of Deeplearn.js, it stopped working:

math.scope(function(keep, track) {
  var i = track(dl.Array3D.fromPixels(rawImageData, 4));
  i = math.multiply(i, track(dl.Scalar.new(1/255, "float32")));
  [ . . . ]
}

It now fails with this message:

The dtypes of the first (int32) and second (float32) input must match

How can I turn my image into float32 values between 0.0 and 1.0?

1

There are 1 answers

1
MattD On

Use the cast function:

math.scope(function(keep, track) {
  var i = track(dl.Array3D.fromPixels(rawImageData, 4));
  i = math.cast(i, "float32");
  i = math.multiply(i, track(dl.Scalar.new(1/255, "float32")));
  [ . . . ]
}