I downloaded the Oxford-IIIT Pet Dataset and used it, but it was trimaps.
This can’t be read directly with tf
Also tried PIL:
It is better to find the answer at https://stackoverflow.com/questions/41777654/opencv-using-a-trimap-image
code show as below:
import io
import os
import tensorflow as tf
import PIL
import matplotlib.pyplot as plt
import numpy as np
with tf.gfile.GFile("Abyssinian_1.png", 'rb') as fid:
encoded_mask_png = fid.read()
encoded_png_io = io.BytesIO(encoded_mask_png)
mask = PIL.Image.open(encoded_png_io)
plt.imshow( np.array(mask) / 2 * 255 )
The effect is as follows:
Then the data read can be turned into an array:
import io
import os
import tensorflow as tf
import PIL
import matplotlib.pyplot as plt
import numpy as np
with tf.gfile.GFile("Abyssinian_1.png", 'rb') as fid:
encoded_mask_png = fid.read()
encoded_png_io = io.BytesIO(encoded_mask_png)
mask = PIL.Image.open(encoded_png_io)
np.array(mask)
effect: