Sorry if this isn’t the right place to post this. Early on in the course, Jeremy mentions that you can train vision models on charts and graphs. I’m trying to test that out and I’m not having much luck.
So I’m attempting to train a vision model to determine the slope of a line. I’ve created 300 line charts with 300 random slopes.
Since I’m asking the model to predict the slope of a line (i.e. a float), I think I’m should use RegressionBlock like so:
from fastai.vision.all import *
# Assuming x_data and y_data are your datasets
def get_line_chart(r): return line_charts[r]
def get_y(r): return random_slopes[r] #y_data[r]
# Define the DataBlock
dblock = DataBlock(blocks=(ImageBlock, RegressionBlock),
get_x=get_line_chart,
get_y=get_y,
splitter=RandomSplitter(valid_pct=0.2, seed=42),
item_tfms=Resize(224))
# Create DataLoaders
dls = dblock.dataloaders(range(300), bs=32)
dls.show_batch looks correct:
I’m creating a vision_learner and calling fit like so:
# Create a Learner
learn = vision_learner(dls, resnet34, metrics=error_rate, n_out=1)
# Train the model
learn.fit(4)
I’ve tried using fine_tune, and I’ve tried using up to 30 epochs. The error_rate never drops below 1.00000 . Sometimes the “valid_loss” gets fairly low, but the predictions aren’t very close.
Any tips? Thank you!