2
$\begingroup$

enter image description hereI have a data set for segmentation project. The dataset have 2 folders containing train folder and annotated_train_data folder, both folders have images. input and label both are images. I want to make a csv file of this dataset to feed into a neural network. what is the easiest and efficient way to make csv file?

./images
./images/train
./images/train/label1.jpg
./images/train/label2.jpg
./images/train/label3.jpg
./images/annotated_train_data
./images/annotated_train_data/label1.jpg
./images/annotated_train_data/label2.jpg
./images/annotated_train_data/label3.jpg
$\endgroup$
7
  • $\begingroup$ How are labels stored in the form of images? Is the tree structure correct? $\endgroup$ – thanatoz Apr 11 '19 at 5:31
  • $\begingroup$ the labels are also images with same name as the input image itself but labels are stored in another folder $\endgroup$ – babayagaa00070 Apr 11 '19 at 6:08
  • $\begingroup$ the label image is annotated version of the input image, and i am trying to use this dataset for segementation purpose. $\endgroup$ – babayagaa00070 Apr 11 '19 at 6:10
  • 1
    $\begingroup$ what do you want in the output csv files? Only the path of each jpg file? $\endgroup$ – aborruso Apr 11 '19 at 8:01
  • $\begingroup$ path of each file is also ok $\endgroup$ – babayagaa00070 Apr 11 '19 at 8:36
2
$\begingroup$
import os
import pandas as pd

BASE_DIR = 'images/'
train_folder = BASE_DIR+'train/'
train_annotation = BASE_DIR+'annotated_train_data/'

files_in_train = sorted(os.listdir(train_folder))
files_in_annotated = sorted(os.listdir(train_annotation))

images=[i for i in files_in_train if i in files_in_annotated]

df = pd.DataFrame()
df['images']=[train_folder+str(x) for x in images]
df['labels']=[train_annotation+str(x) for x in images]

pd.to_csv('files_path.csv', header=None)

Try this.

$\endgroup$
2
  • $\begingroup$ this code made me a list of all the images but how do i generate a csv file including all the images? $\endgroup$ – babayagaa00070 Apr 11 '19 at 8:44
  • $\begingroup$ I have updated the path. This should solve your problem. $\endgroup$ – thanatoz Apr 11 '19 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.