Пример #1
0
 def __init__(self):
     #      logging.debug("create PredictServer. loading model")
     #      rmac_model_proto = './features/deploy_resnet101_normpython.prototxt'
     #      rmac_model_weights = './features/rmac_model.caffemodel'
     #      print rmac_model_proto
     #      self._fDesc = RMACDescriptor(rmac_model_proto, rmac_model_weights)
     self._fDesc = None
     index_feat_path = os.path.join(VISUAL_FEATURE_DIR, 'finearts',
                                    'rmac_index.csv')
     self._searcher = Searcher(index_feat_path, cosine_distance)
     logging.debug("model load successfully")
Пример #2
0
    def _get_searcher(self, museum):
        if museum not in self._searcher:
            index_feat_path = os.path.join(MUSEUM_BASE_DIR,
                                           MUSEUM_DATA_DIR[museum],
                                           'visual_features', 'rmac_index.csv')
            self._searcher[museum] = Searcher(index_feat_path, cosine_distance)

        return self._searcher[museum]
Пример #3
0
class PredictServicer(rpc_pb2_grpc.PredictServicer):
    def __init__(self):
        #      logging.debug("create PredictServer. loading model")
        #      rmac_model_proto = './features/deploy_resnet101_normpython.prototxt'
        #      rmac_model_weights = './features/rmac_model.caffemodel'
        #      print rmac_model_proto
        #      self._fDesc = RMACDescriptor(rmac_model_proto, rmac_model_weights)
        self._fDesc = None
        index_feat_path = os.path.join(VISUAL_FEATURE_DIR, 'finearts',
                                       'rmac_index.csv')
        self._searcher = Searcher(index_feat_path, cosine_distance)
        logging.debug("model load successfully")

    def getDescriptor(self):
        if self._fDesc is None:
            logging.debug("create PredictServer. loading model")
            rmac_model_proto = './features/deploy_resnet101_normpython.prototxt'
            rmac_model_weights = './features/rmac_model.caffemodel'
            print rmac_model_proto
            self._fDesc = RMACDescriptor(rmac_model_proto, rmac_model_weights)
        return self._fDesc

    def PredictPhoto(self, request, context):
        #decode image from request
        img_array = np.asarray(bytearray(request.data), dtype=np.uint8)
        img = cv2.imdecode(img_array, cv2.IMREAD_COLOR)

        t0 = time.time()
        fdesc = self.getDescriptor()
        features = fdesc.describe(img)
        print('feature extraction took {:.3f}s').format(time.time() - t0)
        t0 = time.time()
        if features is not None:
            results = self._searcher.search(features, 5)
        print('Matching took {:.3f}s').format(time.time() - t0)

        #print results
        #process image
        photo_info = "image shape:%s, size:%d, dtype:%s" % (
            img.shape, img.size, img.dtype)
        #  print("predict photo request received. " + photo_info)

        #write response
        return rpc_pb2.PhotoPredictResponse(results=[
            rpc_pb2.PhotoPredictResponse.Result(
                text=photo_info,
                image_url="%s/assets/%s" % (webhost, results[0][0]),
                audio_url="/assets/audio/sample_0.4mb.mp3"),
            rpc_pb2.PhotoPredictResponse.Result(text=photo_info,
                                                image_url="%s/assets/%s" %
                                                (webhost, results[1][0])),
            rpc_pb2.PhotoPredictResponse.Result(text=photo_info,
                                                image_url="%s/assets/%s" %
                                                (webhost, results[2][0]))
        ])
Пример #4
0
ap.add_argument("-q", "--query", required=True, help="Path to the query image")
ap.add_argument("-r",
                "--result_path",
                required=True,
                help="Path to the result path")
args = vars(ap.parse_args())

# initialize the image descriptor
cd = ColorDescriptor((8, 12, 3))

# load the query image and describe it
query = cv2.imread(args["query"])
features = cd.describe(query)

# perform the search
searcher = Searcher(args["index"])
results = searcher.search(features)

# display the query
fig = plt.figure()
ax = fig.add_subplot(4, 3, 1)
query = cv2.cvtColor(query, cv2.COLOR_BGR2RGB)
imgplot = plt.imshow(query)

i = 3

# loop over the results
for (score, resultID) in results:

    i = i + 1
Пример #5
0
import cv2
import numpy as np
import time
import os

import _init_path
from features.rmacdescriptor import RMACDescriptor
from imagesearch.searcher import Searcher, cosine_distance
from features.feature_io import load_model

_ONE_DAY_IN_SECONDS = 60 * 60 * 24
VISUAL_FEATURE_DIR = '../../../../../../../work/data/visual_features'

rmac_model_proto = './features/deploy_resnet101_normpython.prototxt'
rmac_model_weights = './features/rmac_model.caffemodel'
print rmac_model_proto
fDesc = RMACDescriptor(rmac_model_proto, rmac_model_weights)
index_feat_path = os.path.join(VISUAL_FEATURE_DIR, 'finearts-annotated',
                               'rmac_index.csv')
searcher = Searcher(index_feat_path, cosine_distance)

img_file = '/home/pangolins/go/src/github.com/aitour/scene/web/assets/Images/museum/FineArtsQueryHighResolution/painting/587_small.JPG'
t0 = time.time()
features = fDesc.extract_feature(img_file)
print 'feature extraction took %.3f' % (time.time() - t0)
Пример #6
0
# USAGE
# python search.py --query query/100000.png --result-path image

from imagesearch.colordescriptor import ColorDescriptor
from imagesearch.searcher import Searcher
import argparse
import cv2

ap = argparse.ArgumentParser()
ap.add_argument("-q", "--query", required = True,
    help = "path to the query image")
ap.add_argument("-r", "--result-path", required = True,
    help = "Path to the result path")
args = vars(ap.parse_args())

cd = ColorDescriptor((8, 12, 3))

query = cv2.imread(args["query"])
features = cd.describe(query)

searcher = Searcher()
results = searcher.search(features)

cv2.imshow("Query", query)

for (score, resultID) in results:
    result = cv2.imread(args["result_path"] + "/" + resultID)
    cv2.imshow("Result", result)
    cv2.waitKey(0)
Пример #7
0
    "-d",
    "--dataset",
    required=True,
    help="Path to the directory that contains the images we just indexed")
ap.add_argument("-i",
                "--index",
                required=True,
                help="Path to where we stored our index")
args = vars(ap.parse_args())

index = args["index"]
# Load search index and perform image search.
with open(index, 'rb') as f:
    pickle_file = f.read()
index = cPickle.loads(pickle_file)
searcher = Searcher(index)

# Test loop
for (query, queryFeatures) in index.items():
    # Perform the search using the current query.
    results = searcher.search(queryFeatures)
    # Load the query image and display it.
    path = args["dataset"] + "/%s" % (query)
    queryImage = cv2.imread(path)
    plt.imshow(queryImage)
    plt.xticks([]), plt.yticks([])  # Hide the tick values on X and Y axis.
    plt.show()
    print("query: %s" % (query))

    # Initialize the two montages to display the search results.
    # Display the top 10 results with 5 images per output.
Пример #8
0
# USAGE
# python search.py --query query/100000.png --result-path image

from imagesearch.colordescriptor import ColorDescriptor
from imagesearch.searcher import Searcher
import argparse
import cv2

ap = argparse.ArgumentParser()
ap.add_argument("-q", "--query", required=True, help="path to the query image")
ap.add_argument("-r",
                "--result-path",
                required=True,
                help="Path to the result path")
args = vars(ap.parse_args())

cd = ColorDescriptor((8, 12, 3))

query = cv2.imread(args["query"])
features = cd.describe(query)

searcher = Searcher()
results = searcher.search(features)

cv2.imshow("Query", query)

for (score, resultID) in results:
    result = cv2.imread(args["result_path"] + "/" + resultID)
    cv2.imshow("Result", result)
    cv2.waitKey(0)