Пример #1
0
def train_bow_pixel():
    kmeans_sift = KmeansModel()
    sift = Sift()
    if not kmeans_sift.load('kmeans_sift'):
        print 'kmeans_sift not found!'
    if not sift.load():
        print 'no sift data found!'
        exit(1)
Пример #2
0
def train_bow_sift(id_upper):
    if not id_upper:
        id_upper = 3900
    sift = Sift()
    kmeans = KmeansModel()
    image_list = sorted([x for x in os.listdir(DATAPATH) if os.path.splitext(x)[1] == '.jpg' and int(os.path.splitext(x)[0]) < id_upper],key=lambda x: int(os.path.splitext(x)[0]))
    sift.compute(image_list)
    if not kmeans.load('kmeans_sift'):
        kmeans.fit(sift.descriptors_list)
        kmeans.save('kmeans_sift')

    bow = Bow(kmeans)
    # bag of words of samples
    # label indicator1 indicator2 ...
    # ...   ...        ...        ...
    bow.train_sift(sift.descriptors_list)
Пример #3
0
    parser.add_argument('-i',action='store',dest='id_upper',type = int)
    parser.add_argument('-c',action='store_true',help='train classifier')
    parser.add_argument('-f',action='store',dest='file',type=str,help='parser a clothes image')
    args = parser.parse_args()


    if args.cmd == 'train':
        if args.b:
            if args.s:
                train_bow_sift(args.id_upper)
            elif args.p:
                train_bow_pixel()
        if args.c:
            train_clf('pixel')

    if args.cmd == 'test':
        kmeans = KmeansModel()
        kmeans.load('kmeans_pixel')
        clf = RandomForest()
        clf.load()
        data = DataHandler()
        data.load()
        if args.file:
            for res in clf.predict(kmeans,file):
                print int(res),data.tell_label(int(res))

    if args.cmd == 'data':
        data = DataHandler()
        data.parse_data('design.json')
        data.save()