简体   繁体   中英

Load image using csv (labels) for CNN?

I would like to know how am I able to load images with pandas and Keras Image data flow. Currently, my csv file contains

    ID               Category

0   1.png               1
1   2.png               2
2   3.png               1
3   4.png               2
4   5.png               2

and my file directory looks like this

 C:.
|   dataset.csv
|
+---test
|       10.png
|
\---train
    \---train
        +---01
        |       1.png
        |       3.png
        |
        \---02
                2.png
                4.png
                5.png

However , from the different StackOverflow solutions I have found, such as this their train dataset is not sorted into their repsective category folder hence able to flow_from_dataframe .

But in my case, my picture are further sorted into the different folders corresponding to the csv 'Category' which I am unsure how am I able to load the images using csv.

Is there a solution for it? Thanks.

With your file directory structure, you do not need the CSV file to identify your image labels, and actually this is the folder TensorFlow(and most of neural network frameworks) expect you to have. The flow_from_dataframe method is designed to resolve the problem without an expected directory structure . To load your dataset, simply use flow_from_directory method. You may read TensorFlow Official Guide and TensorFlow Document for more examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM