-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Debugger Plugin] Fix a bug in handling string scalar #1131
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,25 +82,42 @@ def array_view(array, slicing=None, mapping=None): | |
| """ | ||
|
|
||
| dtype = str(array.dtype) | ||
| # String-type TensorFlow Tensors are represented as object-type arrays in | ||
| # numpy. We map the type name back to 'string' for clarity. | ||
| if dtype == 'object': | ||
| dtype = 'string' | ||
| sliced_array = (array[command_parser._parse_slices(slicing)] if slicing | ||
| else array) | ||
| shape = sliced_array.shape | ||
| if mapping == "image/png": | ||
| if len(sliced_array.shape) == 2: | ||
| return dtype, shape, array_to_base64_png(sliced_array) | ||
| elif len(sliced_array.shape) == 3: | ||
| raise NotImplementedError( | ||
| "image/png mapping for 3D array has not been implemented") | ||
| else: | ||
| raise ValueError("Invalid rank for image/png mapping: %d" % | ||
| len(sliced_array.shape)) | ||
| elif mapping == 'health-pill': | ||
| health_pill = health_pill_calc.calc_health_pill(array) | ||
| return dtype, shape, health_pill | ||
| elif mapping is None or mapping == '' or mapping.lower() == 'none': | ||
| return dtype, shape, sliced_array.tolist() | ||
|
|
||
| if np.isscalar(sliced_array) and str(dtype) == 'string': | ||
| # When a string Tensor (for which dtype is 'object') is sliced down to only | ||
|
||
| # one element, it becomes a string, instead of an numpy array. | ||
| # We preserve the dimensionality of original array in the returned shape | ||
| # and slice. | ||
| ndims = len(array.shape) | ||
| slice_shape = [] | ||
| for _ in range(ndims): | ||
| sliced_array = [sliced_array] | ||
| slice_shape.append(1) | ||
| return dtype, tuple(slice_shape), sliced_array | ||
| else: | ||
| raise ValueError("Invalid mapping: %s" % mapping) | ||
| shape = sliced_array.shape | ||
| if mapping == "image/png": | ||
| if len(sliced_array.shape) == 2: | ||
| return dtype, shape, array_to_base64_png(sliced_array) | ||
| elif len(sliced_array.shape) == 3: | ||
| raise NotImplementedError( | ||
| "image/png mapping for 3D array has not been implemented") | ||
| else: | ||
| raise ValueError("Invalid rank for image/png mapping: %d" % | ||
| len(sliced_array.shape)) | ||
| elif mapping == 'health-pill': | ||
| health_pill = health_pill_calc.calc_health_pill(array) | ||
| return dtype, shape, health_pill | ||
| elif mapping is None or mapping == '' or mapping.lower() == 'none': | ||
| return dtype, shape, sliced_array.tolist() | ||
| else: | ||
| raise ValueError("Invalid mapping: %s" % mapping) | ||
|
|
||
|
|
||
| IMAGE_COLOR_CHANNELS = 3 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, is this the only way to identify a numpy array that represents a TensorFlow string tensor? Do the methods in this StackOverflow post work at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a tensorflow string-type tensor, the corresponding numpy array has the dtype "object", i.e., different from a regular string-type array in numpy. This is how tensorflow is and we need to live with that.