7
$\begingroup$

I want to create a ML classifier using images just like this example.

I have two classes of images in two different folders. Is there an easier way to import all images from both folders rather than inserting picture by picture?

enter image description here

$\endgroup$
  • 2
    $\begingroup$ something like Import[#] & /@ FileNames["folder/*.jpg"] is what you want. Mathematica has about 3 gigabytes of documentation. $\endgroup$ – acl Aug 22 '14 at 18:40
  • $\begingroup$ You can also use wildcards directly in Import $\endgroup$ – mfvonh Aug 22 '14 at 21:20
6
$\begingroup$

Classify actually supports a nice syntax for this:

Classify[<|"class1" -> Import["class1/*"], "class2" -> Import["class2/*"]|>]
$\endgroup$
1
$\begingroup$

Yes, in order to create your list of images you can use the following piece of code:

Join[
 Thread@Rule[Import["~/Desktop/folder1/*.png"], "Day"],
 Thread@Rule[Import["~/Desktop/folder2/*.png"], "Night"]
 ]

Of course you will need to change the file path and the properties (day/night) appropriately.

$\endgroup$
  • $\begingroup$ That Thread @ Rule stuff is totally unnecessary. Look at the third usage of Classify $\endgroup$ – Taliesin Beynon Sep 24 '14 at 5:30

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.