Skip to content

Commit

Permalink
Support bool value in tf dataset (intel#2401)
Browse files Browse the repository at this point in the history
* support bool value in tf dataset

* fix style
  • Loading branch information
yangw1234 authored Jun 3, 2020
1 parent 16e7605 commit 2739898
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ object TFUtils {
val dataType = t.dataType()

val numericDataTypes = Set(DataType.FLOAT,
DataType.UINT8, DataType.INT32, DataType.INT64, DataType.DOUBLE)
DataType.UINT8, DataType.INT32, DataType.INT64, DataType.DOUBLE, DataType.BOOL)

if (dataType == DataType.STRING) {
val outputTensor = output.asInstanceOf[Tensor[Array[Byte]]]
Expand Down Expand Up @@ -148,6 +148,13 @@ object TFUtils {
val buffer = DoubleBuffer.wrap(arr)
t.writeTo(buffer)
double2float(arr, outputTensor.storage().array(), outputTensor.storageOffset() - 1)
case DataType.BOOL =>
val outputTensor = output.asInstanceOf[Tensor[Float]]
val arr = new Array[Byte](t.numBytes())
assert(t.numBytes() == shape.product, "sanity check")
val buffer = ByteBuffer.wrap(arr)
t.writeTo(buffer)
byte2float(arr, outputTensor.storage().array(), outputTensor.storageOffset() - 1)
}

} else {
Expand Down

0 comments on commit 2739898

Please sign in to comment.