HenrYxZ / object-classification

Python and OpenCV code for training a model for object classification/recognition using images
http://aggiecv.blogspot.com/
20 stars 10 forks source link

Descriptors of NoneType #1

Closed drewbitt closed 4 years ago

drewbitt commented 7 years ago

` File "object-classification\main.py", line 102, in main()

File "object-classification\main.py", line 48, in main des = descriptors.all_descriptors(dataset, dataset.get_train_set(), des_option)

File "object-classification\descriptors.py", line 103, in all_descriptors new_des = descriptors_from_class(dataset, class_img_paths, i, option)

File "object-classification\descriptors.py", line 82, in descriptors_from_class print("Number of descriptors in class: {0}".format(len(des))) TypeError: object of type 'NoneType' has no len()`

Trying to generate a new codebook

Edit: error because your README says "The images don't have to be separated between training and testing, the selection of that is done by the class Dataset" but they do in fact have to be separated between training and testing.

rangeardt commented 7 years ago

can you give me ur config pls? and opencv version , i got some issue with it

rangeardt commented 7 years ago

hi @sidney001, the error came from the dataset folder structure : this should be

dataset/
    class_name/
        train/
              image1.jpg
              image2.jpg
              image3.jpg
              ...
        test/
              image1.jpg
              image2.jpg
              image3.jpg
              ...
    class_name/
        train/
              image1.jpg
              image2.jpg
              image3.jpg
              ...
        test/
              image1.jpg
              image2.jpg
              image3.jpg
              ...
    ....
rangeardt commented 7 years ago

@sidney001 Based on the 101_Caltech dataset structure i can provide my script to generate the classification

Create a bash file on the dataset folder :

#!/bin/bash
mkdir new
cd new/

PATH_FOLDER="/home/thomas/dataset/101_ObjectCategories"
FOLDERS=$(ls $PATH_FOLDER )

for FOLDER in $FOLDERS
do

    number=$(ls "$PATH_FOLDER/$FOLDER" | wc -l)
    half=$((number / 2))
    first=$(ls "$PATH_FOLDER/$FOLDER" | head -n $half)
    second=$(ls "$PATH_FOLDER/$FOLDER" | tail -n $half)
    for photo in $first
    do
        mkdir "$FOLDER" > /dev/null 2>&1
        mkdir "$FOLDER/train" > /dev/null 2>&1
        cp "$PATH_FOLDER/$FOLDER/$photo" "$FOLDER/train/$photo"
    done;

    for photo in $second
    do
        mkdir "$FOLDER" > /dev/null 2>&1
        mkdir "$FOLDER/test" > /dev/null 2>&1
        cp "$PATH_FOLDER/$FOLDER/$photo" "$FOLDER/test/$photo"
    done;
done;

change the path to the Caltech dataset and launch the script, this will create a folder name new inside it each class of the Caltech dataset will be split in 2 folder test and train with half of the class image inside

INPUT :

/home/thomas/dataset/101_ObjectCategories/
├── accordion
│   ├── image_0001.jpg
│   ├── image_0002.jpg
│   ├── image_0003.jpg
│   ├── image_0004.jpg
│   ├── image_0005.jpg
│   ├── image_0006.jpg
│   ├── image_0007.jpg
│   ├── image_0008.jpg
│   ├── image_0009.jpg
│   ├── image_0010.jpg
│   ├── image_0011.jpg
│   ├── image_0012.jpg
│   ├── image_0013.jpg
│   ├── image_0014.jpg
│   ├── image_0015.jpg
│   ├── image_0016.jpg
│   ├── image_0017.jpg
│   ├── image_0018.jpg
│   ├── image_0019.jpg
│   ├── image_0020.jpg
│   ├── image_0021.jpg
│   ├── image_0022.jpg
│   ├── image_0023.jpg
│   ├── image_0024.jpg
│   ├── image_0025.jpg
│   ├── image_0026.jpg
│   ├── image_0027.jpg
│   ├── image_0028.jpg
│   ├── image_0029.jpg
│   ├── image_0030.jpg
│   ├── image_0031.jpg
│   ├── image_0032.jpg
│   ├── image_0033.jpg
│   ├── image_0034.jpg
│   ├── image_0035.jpg
│   ├── image_0036.jpg
│   ├── image_0037.jpg
│   ├── image_0038.jpg
│   ├── image_0039.jpg
│   ├── image_0040.jpg
│   ├── image_0041.jpg
│   ├── image_0042.jpg
│   ├── image_0043.jpg
│   ├── image_0044.jpg
│   ├── image_0045.jpg
│   ├── image_0046.jpg
│   ├── image_0047.jpg
│   ├── image_0048.jpg
│   ├── image_0049.jpg
│   ├── image_0050.jpg
│   ├── image_0051.jpg
│   ├── image_0052.jpg
│   ├── image_0053.jpg
│   ├── image_0054.jpg
│   └── image_0055.jpg
├── airplanes
│   ├── image_0001.jpg
│   ├── image_0002.jpg
│   ├── image_0003.jpg
│   ├── image_0004.jpg
...

OUTPUT:

.
├── generatedataset.sh
└── new
    ├── accordion
    │   ├── test
    │   │   ├── image_0029.jpg
    │   │   ├── image_0030.jpg
    │   │   ├── image_0031.jpg
    │   │   ├── image_0032.jpg
    │   │   ├── image_0033.jpg
    │   │   ├── image_0034.jpg
    │   │   ├── image_0035.jpg
    │   │   ├── image_0036.jpg
    │   │   ├── image_0037.jpg
    │   │   ├── image_0038.jpg
    │   │   ├── image_0039.jpg
    │   │   ├── image_0040.jpg
    │   │   ├── image_0041.jpg
    │   │   ├── image_0042.jpg
    │   │   ├── image_0043.jpg
    │   │   ├── image_0044.jpg
    │   │   ├── image_0045.jpg
    │   │   ├── image_0046.jpg
    │   │   ├── image_0047.jpg
    │   │   ├── image_0048.jpg
    │   │   ├── image_0049.jpg
    │   │   ├── image_0050.jpg
    │   │   ├── image_0051.jpg
    │   │   ├── image_0052.jpg
    │   │   ├── image_0053.jpg
    │   │   ├── image_0054.jpg
    │   │   └── image_0055.jpg
    │   └── train
    │       ├── image_0001.jpg
    │       ├── image_0002.jpg
    │       ├── image_0003.jpg
    │       ├── image_0004.jpg
    │       ├── image_0005.jpg
    │       ├── image_0006.jpg
    │       ├── image_0007.jpg
    │       ├── image_0008.jpg
    │       ├── image_0009.jpg
    │       ├── image_0010.jpg
    │       ├── image_0011.jpg
    │       ├── image_0012.jpg
    │       ├── image_0013.jpg
    │       ├── image_0014.jpg
    │       ├── image_0015.jpg
    │       ├── image_0016.jpg
    │       ├── image_0017.jpg
    │       ├── image_0018.jpg
    │       ├── image_0019.jpg
    │       ├── image_0020.jpg
    │       ├── image_0021.jpg
    │       ├── image_0022.jpg
    │       ├── image_0023.jpg
    │       ├── image_0024.jpg
    │       ├── image_0025.jpg
    │       ├── image_0026.jpg
    │       └── image_0027.jpg
    ├── airplanes
    │   ├── test
    │   │   ├── image_0401.jpg
    │   │   ├── image_0402.jpg
    │   │   ├── image_0403.jpg
    │   │   ├── image_0404.jpg
    │   │   ├── image_0405.jpg
    │   │   ├── image_0406.jpg
    │   │   ├── image_0407.jpg
    │   │   ├── image_0408.jpg
    │   │   ├── image_0409.jpg
    │   │   ├── image_0410.jpg
    │   │   ├── image_0411.jpg
    │   │   ├── image_0412.jpg
    │   │   ├── image_0413.jpg
    │   │   ├── image_0414.jpg
    │   │   ├── image_0415.jpg
    │   │   ├── image_0416.jpg
    │   │   ├── image_0417.jpg
    │   │   ├── image_0418.jpg
    │   │   ├── image_0419.jpg
    │   │   ├── image_0420.jpg
    │   │   ├── image_0421.jpg
    │   │   ├── image_0422.jpg
    │   │   ├── image_0423.jpg
...

then change the path to the dataset inside the constant.py

exemple :

    NUMPY_DELIMITER = ","
    PICKLE_PROTOCOL = 2
    DATASET_PATH = "dataset/new"
    ORB_FEAT_OPTION = 1
    SIFT_FEAT_OPTION = 2
    TESTING_IMG_PATH = "dataset/train/accordion/image_0001.jpg"
    ORB_FEAT_NAME = "ORB"
    SIFT_FEAT_NAME = "SIFT"
    GENERATE_OPTION = 1
    FILES_DIR_NAME = "files"
    TRAIN_TXT_FILE = "train.txt"
    TEST_TXT_FILE = "test.txt"
    STEP_PERCENTAGE = 20
sidney001 commented 7 years ago

@rangeardt Thanks for your sharing. I'll try your script.

wohnxi commented 7 years ago

@rangeardt Thanks for your script. I generated the right dataset structure and the error was gone. However, the new error come out. Traceback (most recent call last):

File "", line 1, in runfile('C:/Users/frdc-sh/Desktop/object-classification-master/main.py', wdir='C:/Users/frdc-sh/Desktop/object-classification-master')

File "C:\Users\frdc-sh\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile execfile(filename, namespace)

File "C:\Users\frdc-sh\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py", line 87, in execfile exec(compile(scripttext, filename, 'exec'), glob, loc)

File "C:/Users/frdc-sh/Desktop/object-classification-master/main.py", line 102, in main()

File "C:/Users/frdc-sh/Desktop/object-classification-master/main.py", line 78, in main result_matrix = np.reshape(result, (len(classes), test_count))

File "C:\Users\frdc-sh\Anaconda2\lib\site-packages\numpy\core\fromnumeric.py", line 232, in reshape return _wrapfunc(a, 'reshape', newshape, order=order)

File "C:\Users\frdc-sh\Anaconda2\lib\site-packages\numpy\core\fromnumeric.py", line 57, in _wrapfunc return getattr(obj, method)(*args, **kwds)

ValueError: cannot reshape array of size 636 into shape (11,23)

The parameter is original as I set 'is_interactive=False'. The error seems 'np.reshape' the array doesn't meet the size of the orginal array. How do you settle this error?

rangeardt commented 7 years ago

@wohnxi i got the same issue, i open a new thread for it and try to figure it out

rangeardt commented 7 years ago

@wohnxi New thread for this issue

kakri commented 7 years ago

I had created test and train folders inside dataset folder for each of the class and the code is running fine. But I'm getting confusion matrix as an output instead of the accuracy.VLADs testing vectors saved on file files/VLADS_test_3_ORB.mat Confusion Matrix = [[3 0 0] [1 2 0] [0 0 3]] Log saved on files/log_3_ORB_LINEAR.txt. Press [Enter] to exit ... This is how the program is running. I'm using opencv3 version and I know that i cant use SIFT without opencv_contrib.

HenrYxZ commented 4 years ago

I'm closing this Issue since the README was updated, thanks for letting me know about it