# Building a classifier for images

I tried to build a classifier for some images that I have with the following code:

class1 = Import /@
FileNames["*",
"location1"];

class2 = Import /@
FileNames["*",
"location2"];

classifier =
Classify[Join[# -> "H" & /@
class1, # -> "C" & /@
class2]];


I believe that this would work, but it crashes with an out of memory error after the system tries to use more than 64GB of RAM.

Total size of all the images in collection is 42MB.

How can I build a classifier that in such a way that it doesn't require more than 64GB of RAM?

Update: I converted all the files to .jpg, and the issue remained.

• What is the file format of the images? – C. E. Mar 9 '16 at 0:44
• @C.E. .tiff. Does it matter? – soandos Mar 9 '16 at 0:44
• Not always, but it can. There is a discussion specifically on .tiff images and memory consumption here. – C. E. Mar 9 '16 at 0:53
• @C.E. h'm. Should what format should I convert them to as a test? – soandos Mar 9 '16 at 0:54
• There's no simple answer to that question. You begin by guessing "what values are relevant in these images for an algorithm that would need to distinguish between them?" and then you'd extract values for each of those. So for example, you might extract the brightness of each image. Or maybe how green the image is. You then have a vector of each of these features and use these vectors instead of the image. – Searke Mar 9 '16 at 4:34

You might try ImageIdentify[image,category,n] to generate "feature vectors" consisting of n words. If you are lucky, the best n matches might contain enough information to distinguish the two kinds of images. The advantage of this approach is that you would leverage all the sophisticated image processing inherent in ImageIdentify and the classifier needs to only function on the words. So in outline, for each image you would get a list like
feat = ImageIdentify[image, All, 5]

which returns a 5-vector of where feat[[All, 2]] contains the best-match words. These sets of words could then be used in the Classify step.