question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flash fails to load image labels from CSV on Kaggle RANZCR CLiP - Catheter and Line Position Challenge

See original GitHub issue

🐛 Bug

The master code does not properly load labels from CSV for image classification. Trying to get a baseline working for the Catheter and Line Position Challenge and am currently blocked.

To Reproduce

Steps to reproduce the behavior:

  1. !pip install git+https://github.com/PyTorchLightning/lightning-flash.git@master
  2. Run ‘…’

import os
import flash
from flash.core.data import download_data
from flash.core.finetuning import FreezeUnfreeze
from flash.vision import ImageClassificationData, ImageClassifier

data = ImageClassificationData(
    train_filepaths='/kaggle/input/ranzcr-clip-catheter-line-classification/train', 
    train_labels='/kaggle/input/ranzcr-clip-catheter-line-classification/train.csv', 
    valid_filepaths='/kaggle/input/ranzcr-clip-catheter-line-classification/test', 
    valid_labels='/kaggle/input/ranzcr-clip-catheter-line-classification/test.csv'
)

Stack Trace

Successfully installed datasets-1.2.1 lightning-flash-0.2.1.dev0 pandas-1.1.2 pycocotools-2.0.2 pytorch-lightning-1.2.0rc0 pytorch-lightning-bolts-0.3.0 pytorch-tabnet-3.1.1 rouge-score-0.0.4 scikit-learn-0.24.0 torch-1.7.1 torchvision-0.8.2 tqdm-4.49.0 xxhash-2.0.0 TypeError

TypeError Traceback (most recent call last) <ipython-input-5-1ea2eb98cece> in <module> 3 train_labels=‘/kaggle/input/ranzcr-clip-catheter-line-classification/train.csv’, 4 valid_filepaths=‘/kaggle/input/ranzcr-clip-catheter-line-classification/test’, ----> 5 valid_labels=‘/kaggle/input/ranzcr-clip-catheter-line-classification/test.csv’ 6 )

/opt/conda/lib/python3.7/site-packages/pytorch_lightning/core/datamodule.py in call(cls, *args, **kwargs) 48 49 # Get instance of LightningDataModule by mocking its init via call —> 50 obj = type.call(cls, *args, **kwargs) 51 52 return obj

TypeError: init() got an unexpected keyword argument ‘train_filepaths’ init() got an unexpected keyword argument ‘train_filepaths’ Enter console command here

Expected behavior

Data Module loads labels without issue

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
teddykokercommented, Feb 17, 2021

You need to use ImageClassificationData.from_filepaths(), and then supply the filenames and labels as lists. The image paths will need to be extracted from the csv, something like:

# load in csv
df = pd.read_csv("train.csv")

# extract ids
ids = list(df["StudyInstanceUID"])

# get filenames by appending .jpg to id
filenames = [f"{id}.jpg" for id in ids]

# from https://www.kaggle.com/heyytanay/torch-trainer-augmentations-nfnets
# get labels for each id
labels = [label = df[df['StudyInstanceUID'] == id].values.tolist()[0][1:-1] for id in ids] 


# hypothetically you could do this, if it wasn't multilabel, see note below
data = ImageClassificationData.from_filepaths(train_filepaths=filenames, train_labels=labels, ...)

NOTE: looking at the Kaggle competition this data appears to be multi-label, which the ImageClassificationData does not support (yet?)

Read more comments on GitHub >

github_iconTop Results From Across the Web

RANZCR CLiP - Catheter and Line Position Challenge - Kaggle
In this competition, you'll detect the presence and position of catheters and lines on chest x-rays. Use machine learning to train and test...
Read more >
RANZCR CLiP - Catheter and Line Position Challenge - Kaggle
RANZCR CLiP - Catheter and Line Position Challenge. Classify the presence and correct placement of tubes on chest x-rays to save lives. $50,000Prize...
Read more >
RANZCR CLiP - Catheter and Line Position Challenge - Kaggle
RANZCR CLiP - Catheter and Line Position Challenge. Classify the presence and correct placement of tubes on chest x-rays to save lives. $50,000Prize...
Read more >
RANZCR CLiP - Catheter and Line Position Challenge - Kaggle
RANZCR CLiP - Catheter and Line Position Challenge. Classify the presence and correct placement of tubes on chest x-rays to save lives. $50,000Prize...
Read more >
RANZCR CLiP - Catheter and Line Position Challenge - Kaggle
RANZCR CLiP - Catheter and Line Position Challenge. Classify the presence and correct placement of tubes on chest x-rays to save lives. $50,000Prize...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found