(arr)
| 28 | |
| 29 | |
| 30 | def image_to_nhwc(arr): |
| 31 | if arr.ndim == 4: |
| 32 | pass |
| 33 | elif arr.ndim == 3: |
| 34 | if arr.shape[-1] in [1, 3, 4]: |
| 35 | arr = arr[np.newaxis, :] |
| 36 | else: |
| 37 | arr = arr[:, :, :, np.newaxis] |
| 38 | elif arr.ndim == 2: |
| 39 | arr = arr[np.newaxis, :, :, np.newaxis] |
| 40 | else: |
| 41 | raise ValueError("Array of shape {} is not an image!".format(arr.shape)) |
| 42 | return arr |
| 43 | |
| 44 | |
| 45 | class MonitorBase(Callback): |