Siavash S
Siavash S

Reputation: 43

Using TFX for designing image piplines

When reading the documentation for TFX, especially in the parts related to pre-processing of the data, I would think the pipeline design is more appropiate for categorical features.

I wanted to know whether TFX could also be used for pipelines involving images.

Upvotes: 3

Views: 995

Answers (1)

RakTheGeek
RakTheGeek

Reputation: 425

Yes, TFX could also be used for pipelines involving images.

Especially, in the parts related to pre-processing the data, as per my knowledge, there are no in-built functions in Tensorflow Transform.

But the Transformations can be made using Tensorflow Ops. For example, Image Augmentation can be done using tf.image, and so on.

Sample code for Transformation of Images, i.e., converting an image from Color to Grey Scale, by dividing the value of each pixel by 255, using Tensorflow Transform is shown below:

def preprocessing_fn(inputs):
  """Preprocess input columns into transformed columns."""
  # Since we are modifying some features and leaving others unchanged, we
  # start by setting `outputs` to a copy of `inputs.
  outputs = inputs.copy()

  # Convert the Image from Color to Grey Scale. 
  # NUMERIC_FEATURE_KEYS is the list of names of Columns of Values of Pixels
  for key in NUMERIC_FEATURE_KEYS:
    outputs[key] = tf.divide(outputs[key], 255)

  outputs[LABEL_KEY] = inputs[LABEL_KEY]

  return outputs

Upvotes: 1

Related Questions