Loading Data into fastai

(Ayush Patel) #1

HI ,So i am trying to use fastai to predict various attributes present in an image and for that i have a csv file that looks something like this.How do i load this into fastai.Thanks for help in advance

(Ehab Ibrahim) #2

FastAI deals with pandas datadrames “you can check pandas python library”
The way you can read your csv file and use it within FastAI is to first read it as a pandas dataframe. This can be done using the function:
import pandas as pd
You can read more about pandas.read_csv() from their documentation

(Ayush Patel) #3

Okay so i tried loading data using ImageClassifier_fromcsv but in my csv files i am already having labels in One Hot Encoded format .Now When i try to use this I get only two classes 0 and 1 instead of the various attributes that i should have got.The result that i am getting is this

whereas the way my csv ius formatted is this:

Thanks in advance for your help

(Constantin) #4

fastai is using pandas.read_csv() to load .csv files. The latter tries to parse the file automatically, which mostly succeeds, but can fail, if you have a special format. A couple of things to try:

  • Check the exact details of your file. E.g. what separator are you using? For some reason fastai uses a fixed separator cat_separator=" ". If yours happens to use commas or so, then loading will fail or produce funny results. If you run into such a case, you can either a) rewrite your csv file to suit fastai’s preferences (using pandas) or b) overwrite part of the ImageClassifierData.from_csv() to pass more command line arguments, such as the separator.
  • Check the docstring of pd.read_csv(), which could give you more details on what parameters to set.