def get_scaled_page(page): staffsize = single_staffdist(page) shape = tf.shape(page.image) a = tf.cast(SCALED_STAFFSIZE, tf.float32) / tf.cast(staffsize, tf.float32) b = 2048.0 / tf.cast(tf.reduce_max(tf.shape(page.image)), tf.float32) scale = tf.cond((a < 0) | (b < a), lambda: b, lambda: a) new_shape = tf.cast(tf.cast(shape, tf.float32) * scale, tf.int32) resized = util.scale(page.image, new_shape) return Page(pad_square(resized, 2048))
def get_square(img, max_size=MAX_SIZE): old_shape = tf.shape(img) new_shape, = tf.py_func(_resized_shape, [old_shape, max_size], [old_shape.dtype]) resized = util.scale(img, new_shape) return pad_square(resized, MAX_SIZE)
def get_square(img, max_size=MAX_SIZE): old_shape = tf.shape(img) new_shape, = tf.py_func( _resized_shape, [old_shape, max_size], [old_shape.dtype]) resized = util.scale(img, new_shape) return pad_square(resized, MAX_SIZE)