Assert that we are working with properly shaped image. Args: image: >= 3-D Tensor of size [*, height, width, depth] require_static: If `True`, requires that all dimensions of `image` are known and non-zero. Raises: ValueError: if image.shape is not a [>= 3] vector. Returns
(image, require_static=True)
| 198 | |
| 199 | |
| 200 | def _CheckAtLeast3DImage(image, require_static=True): |
| 201 | """Assert that we are working with properly shaped image. |
| 202 | |
| 203 | Args: |
| 204 | image: >= 3-D Tensor of size [*, height, width, depth] |
| 205 | require_static: If `True`, requires that all dimensions of `image` are known |
| 206 | and non-zero. |
| 207 | |
| 208 | Raises: |
| 209 | ValueError: if image.shape is not a [>= 3] vector. |
| 210 | |
| 211 | Returns: |
| 212 | An empty list, if `image` has fully defined dimensions. Otherwise, a list |
| 213 | containing an assert op is returned. |
| 214 | """ |
| 215 | try: |
| 216 | if image.get_shape().ndims is None: |
| 217 | image_shape = image.get_shape().with_rank(3) |
| 218 | else: |
| 219 | image_shape = image.get_shape().with_rank_at_least(3) |
| 220 | except ValueError: |
| 221 | raise ValueError("'image' must be at least three-dimensional.") |
| 222 | if require_static and not image_shape.is_fully_defined(): |
| 223 | raise ValueError('\'image\' must be fully defined.') |
| 224 | if any(x == 0 for x in image_shape): |
| 225 | raise ValueError('all dims of \'image.shape\' must be > 0: %s' % |
| 226 | image_shape) |
| 227 | if not image_shape.is_fully_defined(): |
| 228 | return [ |
| 229 | check_ops.assert_positive( |
| 230 | array_ops.shape(image), |
| 231 | ["all dims of 'image.shape' " |
| 232 | 'must be > 0.']), |
| 233 | check_ops.assert_greater_equal( |
| 234 | array_ops.rank(image), |
| 235 | 3, |
| 236 | message="'image' must be at least three-dimensional.") |
| 237 | ] |
| 238 | else: |
| 239 | return [] |
| 240 | |
| 241 | |
| 242 | def _AssertGrayscaleImage(image): |
no test coverage detected