Tensorflow layer reversal

Hi I want some help. I would like to develop a TensorFlow model
The idea is that given ‘value’ defined as follows:

import cv2
im = cv2.imread("anyimage.jpg")
_, buffer = cv2.imencode('.jpg', im)
jpg_as_text = base64.b64encode(buffer)
value=jpg_as_text.decode('utf-8')

Create tensorflow layers to do the reverse process and obtain a tensor with the original image, these layers must be exportable with the model.save(‘folder’) option

My goal is to change the input of my models to this new form
not training needed, not dataset needed because I have to provide the value and in that layer(or layers) reverse function will be coded and it than returns the original image as tensor

Hi @Muhammad_Talha, I don’t think you require a model for your case you can easily do it with the help of below code.

def decode_image(value):
    image_binary = base64.b64decode(value)
    image_array = np.frombuffer(image_binary, np.uint8)
    image = cv2.imdecode(image_array, cv2.IMREAD_COLOR)
    tensor = tf.convert_to_tensor(image, dtype=tf.float32)
    return tensor

Thank You.