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

rocal_pybind - bug fix for one hot encoded labels #1038

Merged
merged 3 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions rocAL/rocAL_pybind/amd/rocal/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,13 +217,15 @@ def copyToTensorNCHW(self, array, multiplier, offset, reverse_channels, tensor_
multiplier[0], multiplier[1], multiplier[2], offset[0], offset[1], offset[2], (1 if reverse_channels else 0))
def GetOneHotEncodedLabels(self, array, device):
if device=="cpu":
return b.getOneHotEncodedLabels(self._handle, ctypes.c_void_p(array.data_ptr()), self._numOfClasses, 0)
if (isinstance(array,np.ndarray)):
b.getOneHotEncodedLabels(self._handle, array.ctypes.data_as(ctypes.c_void_p), self._numOfClasses, 0)
else: #torch tensor
return b.getOneHotEncodedLabels(self._handle, ctypes.c_void_p(array.data_ptr()), self._numOfClasses, 0)
if device=="gpu":
return b.getOneHotEncodedLabels(self._handle, ctypes.c_void_p(array.data_ptr()), self._numOfClasses, 1)

def GetOneHotEncodedLabels_TF(self, array):
# Host destination only
return b.getOneHotEncodedLabels(self._handle, array.ctypes.data_as(ctypes.c_void_p), self._numOfClasses, 0)
if (isinstance(array,cp.ndarray)):
b.getOneHotEncodedLabels(self._handle, array.data.ptr, self._numOfClasses, 1)
else: #torch tensor
return b.getOneHotEncodedLabels(self._handle, ctypes.c_void_p(array.data_ptr()), self._numOfClasses, 1)

def set_outputs(self, *output_list):
self._output_list_length = len(output_list)
Expand Down
2 changes: 1 addition & 1 deletion rocAL/rocAL_pybind/amd/rocal/plugin/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def __next__(self):
if(self.loader._name == "labelReader"):
if(self.loader._oneHotEncoding == True):
self.loader.GetOneHotEncodedLabels(self.labels, self.device)
self.labels_tensor = self.labels.view(-1, self.bs, self.loader._numOfClasses).long()
self.labels_tensor = self.labels.reshape(-1, self.bs, self.loader._numOfClasses)
else:
if self.display:
for i in range(self.bs):
Expand Down
2 changes: 1 addition & 1 deletion rocAL/rocAL_pybind/amd/rocal/plugin/tf.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __next__(self):
elif (self.loader._name == "TFRecordReaderClassification"):
if(self.loader._oneHotEncoding == True):
self.labels = np.zeros((self.bs)*(self.loader._numOfClasses),dtype = "int32")
self.loader.GetOneHotEncodedLabels_TF(self.labels)
self.loader.GetOneHotEncodedLabels(self.labels, device="cpu")
self.labels = np.reshape(self.labels, (-1, self.bs, self.loader._numOfClasses))
else:
self.labels = np.zeros((self.bs),dtype = "int32")
Expand Down