in machine_learning/ml_infrastructure/inference-server-performance/server/scripts/tensorrt-optimization.py [0:0]
def preprocess(record):
image_bytes, label = deserialize_image_record(record)
shape = tf.image.extract_jpeg_shape(image_bytes)
image_height = shape[0]
image_width = shape[1]
padded_center_crop_size = tf.cast(
((IMAGE_SIZE / (IMAGE_SIZE + CROP_PADDING)) *
tf.cast(tf.minimum(image_height, image_width), tf.float32)),
tf.int32)
offset_height = ((image_height - padded_center_crop_size) + 1) // 2
offset_width = ((image_width - padded_center_crop_size) + 1) // 2
crop_window = tf.stack([offset_height, offset_width,
padded_center_crop_size, padded_center_crop_size])
image = tf.image.decode_and_crop_jpeg(image_bytes, crop_window, channels=3)
image = tf.image.resize_bicubic([image], [IMAGE_SIZE, IMAGE_SIZE])[0]
image = tf.reshape(image, [IMAGE_SIZE, IMAGE_SIZE, 3])
image = tf.image.convert_image_dtype(image, tf.float32)
return image, label