Hello,
I’m working on a regression problem using a cat dataset from kaggle. It is basically pictures of cats with landmarks of its facial features.
Anyway, the images comes in different sizes and I have to resize them for the datablock api to read the images without warnings. But first I need to rescaled the points with this small function:
from fastai.vision import *
import os
data_path = os.path.join(os.getcwd(), "data")
def get_labels(file):
points_df = pd.read_csv(str(file) + ".cat", sep=" ", header=None)
points = (points_df.values[0][1:-1]).reshape((-1, 2))
points[:, [0, 1]] = points[:, [1, 0]]
old_size = open_image(os.path.join(file)).size
points_ratio = np.array([224,224]) / np.array(old_size)
points = Tensor(points * points_ratio)
return Tensor(points)
And I can plot a single image like this:
img_path = os.path.join(data_path, "CAT_01", "00000256_006.jpg")
img = open_image(img_path).resize(224)
points = ImagePoints(FlowField(img.size, get_labels(img_path)))
img.show(y=points, figsize=(9, 6))
However, when I create a databunch using the datablock API, and try to show the images using show_batch
, the points seems way off:
data = (PointsItemList.from_folder(data_path, extensions=".jpg")
.split_by_rand_pct() # Later split by folder
.label_from_func(get_labels)
.transform(get_transforms(), size=(224, 224))
.databunch().normalize(imagenet_stats)
)
data.show_batch(1, figsize=(9, 6))
Am I missing something?
Thanks