9

How can I work with my own dataset in scikit-learn? Scikit Tutorial always take as example to load his dataset (digit dataset, flower dataset...)

http://scikit-learn.org/stable/datasets/index.html ie: from sklearn.datasets import load_iris

I have my images and I have no idea how create new one.

Particularly, for starting, i use this example i found (i use library opencv):

img =cv2.imread('telamone.jpg')

# Convert them to grayscale
imgg =cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

# SURF extraction
surf = cv2.SURF()
kp, descritors = surf.detect(imgg,None,useProvidedKeypoints = False)

# Setting up samples and responses for kNN
samples = np.array(descritors)
responses = np.arange(len(kp),dtype = np.float32)

I would like to extract features of a set of images, in a way useful to implement a machine learning algorithm!

Matt
  • 17,290
  • 7
  • 57
  • 71
postgres
  • 2,242
  • 5
  • 34
  • 50

1 Answers1

5

You would first need to clearly define what you are trying to achieve: "extract feature to a set of images, in a way useful to implement a machine learning algorithm!" is much too vague to give you any guidance.

Are you trying to do:

  • image classification of the picture as a whole (e.g. indoor scene vs outdoor scene)?

  • object recognition (e.g. recognizing several instances of the same object in different pictures) inside sub-parts of a set of pictures, maybe using a scan procedures with windows of various sizes?

  • object detection and class-based categorization (e.g. finding all occurrences of cars or pedestrians in pictures and a bounding box around each occurrence of instances of those classes)?

  • full picture semantic parsing a.k.a. segmentation of the pixels + class categorization of each segment (build, road, people, trees)...

Each of those tasks will require different pipelines (feature extraction + machine learning models combo).

You should probably start by reading a book on the subject, for instance: http://szeliski.org/Book/

Also as a side note, stackoverflow is probably not the best place to ask such open ended questions.

Matt
  • 17,290
  • 7
  • 57
  • 71
ogrisel
  • 39,309
  • 12
  • 116
  • 125
  • it could be image classification and comparison and object detection? I have archeological signs, an image for every archeological sign. I need to extract features (like surf, or contour with canny algorithm) for every image, i saw scikit use "dataset" where load his default images like iris, or digits. i would like to compare this feature and calculating it's similarity. – postgres Nov 30 '12 at 14:04
  • 1
    For whole image classification (assuming the images are centered and zoomed on the signs), scikit-learn would expect a numpy array with shape `(n_images, n_features)` for the input data and a numpy array with shape `(n_images,)` for the target to predict with different integers for each different signs. The way to extract the features. Maybe you could try HoG features from scikit-image that provide fixed sized arrays instead of keypoint-based features like SURF or SIFT that have a dynamic structure (the number of keypoint varies from one image to another). – ogrisel Nov 30 '12 at 18:10
  • 2
    If you really want to use SURF features you would probably need to use a clustering algorithm to build a vocabulary of 1000 visual words (or more) on all the SURF feature vectors extracted from the corpus. Then for each image assign the extracted SURF feature vector to their nearest centroid (quantization) to have each picture encoded as a Bag of (visual) Words (BoW). But this is a all lot more complicated to do if you are new to numpy / scikit-learn and computer vision in general. – ogrisel Nov 30 '12 at 18:21
  • Thank you very much! I read HoG feature is for human recognition, i think i need an algorithm recognizing sign's edges , similar an OCR software who recognize text, or not? Or HoG is good also for my purpose? – postgres Dec 05 '12 at 00:55
  • Just try. It's probably dependent on your data. – ogrisel Dec 05 '12 at 10:33
  • Ok, Hog feature work for a image. Which is the next step? here (http://scikit-image.org/docs/dev/auto_examples/plot_hog.html#example-plot-hog-py) talks about:"The final step collects the HOG descriptors from all blocks of a dense overlapping grid of blocks covering the detection window into a combined feature vector for use in the window classifier." Do i implement a window classifier? Or an SVM? And what do i do with numpy array (n_images, n_features) ? I so really confused! – postgres Dec 05 '12 at 14:28
  • Stackoverflow is really not the best place to answer such open ended questions whose answer involve a complex pipeline of various tools and mathematical concepts: object classification is still an active research area. Please either ask small specific, self-holding programming questions or register to graduate course on computer vision and machine learning (or read books). – ogrisel Dec 05 '12 at 15:33
  • this book: http://szeliski.org/Book/, it's only theorical (math equations..) or there is also code and all different pipelines, like you said, to achieve my purpose? – postgres Dec 07 '12 at 18:23
  • 1
    i find partially answer to my question here (creating dataset): unfortuantely not in scikit: http://www.coccidia.icb.usp.br/coccimorph/tutorials/Tutorial-2-Creating-a-Dataset.pdf – postgres Dec 07 '12 at 22:00
  • @ogrisel IMO you answer about nothing. The question is clear: how to prepare dataset like IRISes with own images. But you are talking about complexity, investigation, different approaches etc and nothing about point of the question. – Roman Podlinov Jul 30 '13 at 05:25
  • @Roman scikit-learn takes any numpy array as input: in iris it's not based on image, so it's easy: you [load the numerical values of a CSV file](https://github.com/scikit-learn/scikit-learn/blob/master/sklearn/datasets/base.py#L216). The iris dataset was created by having a human measure petal and sepal length manually. So this is not a computer vision problem. Computer vision problems on the other hand are much more complex. For CV you need task specific feature extractions with tools like OpenCV. scikit-learn is not a CV library it-self. – ogrisel Jul 30 '13 at 08:50
  • There is no easy answer: the kind of features you need to extract is dependent on your goal. Do you want to do object recognition, image classification, image segmentation? Something else? Read a book about OpenCV if you want to know how to do those things. It cannot fit on a stackoverflow answer. – ogrisel Jul 30 '13 at 08:53
  • @ogrisel Thank you so much! Now your answers is much more useful for me. Could you please slightly update your answer and I will re-vote it UP? – Roman Podlinov Aug 01 '13 at 13:17