इमेज खोजने वालों को शामिल करें

इमेज सर्च की मदद से, इमेज के डेटाबेस में मिलती-जुलती इमेज खोजी जा सकती हैं. यह यह खोज क्वेरी को हाई-डाइमेंशन वाले वेक्टर में एम्बेड करके काम करता है जो इस क्वेरी का सिमैंटिक मतलब, इसके बाद समानता की खोज, पहले से तय, कस्टम इंडेक्स, जो ScaNN (बड़े और नज़दीकी पड़ोसी)

इसके उलट इमेज क्लासिफ़िकेशन, पहचाने जा सकने वाले आइटम की संख्या बढ़ाने के लिए, फिर से ट्रेनिंग लेने की ज़रूरत नहीं होती पूरा मॉडल. इंडेक्स को फिर से बनाकर नए आइटम जोड़े जा सकते हैं. यह भी इमेज के बड़े (1 लाख से ज़्यादा आइटम) डेटाबेस के साथ काम करने की सुविधा देता है.

अपनी पसंद के मुताबिक इमेज खोजने वाले टूल को डिप्लॉय करने के लिए, टास्क लाइब्रेरी ImageSearcher एपीआई का इस्तेमाल करें आपके मोबाइल ऐप्लिकेशन में.

ImageSearcher API की मुख्य सुविधाएं

  • इनपुट के रूप में एक इमेज लेता है, एम्बेड करके एक्सट्रैक्शन करता है और आस-पास की जगहों के बारे में खोज करने की सुविधा मिलती है.

  • इनपुट इमेज प्रोसेसिंग, जिसमें रोटेशन, साइज़ बदलना, और कलर स्पेस शामिल हैं कन्वर्ज़न होता है.

  • इनपुट इमेज के लिए दिलचस्पी का क्षेत्र.

ज़रूरी शर्तें

ImageSearcher एपीआई का इस्तेमाल करने से पहले, आपको खोज करने के लिए छवियों का कस्टम संग्रह. ऐसा करने के लिए मॉडल मेकर सर्चर एपीआई बदलाव करके, ट्यूटोरियल.

इसके लिए आपको इनकी ज़रूरत होगी:

इस चरण के बाद, आपके पास एक स्टैंडअलोन TFLite सर्च करने वाला मॉडल होना चाहिए (उदाहरण के लिए, mobilenet_v3_searcher.tflite), जो इस सुविधा के साथ ओरिजनल इमेज एम्बेडर मॉडल है जो इंडेक्स TFLite मॉडल का मेटाडेटा.

Java में अनुमान चलाएं

पहला चरण: Gradle डिपेंडेंसी और अन्य सेटिंग इंपोर्ट करना

.tflite सर्चर मॉडल की फ़ाइल को, Android की ऐसेट डायरेक्ट्री में कॉपी करें मॉड्यूल जहां मॉडल चलाया जाएगा. बताएं कि फ़ाइल कंप्रेस किया हुआ है और TensorFlow Lite लाइब्रेरी को मॉड्यूल के build.gradle में जोड़ें फ़ाइल:

android {
    // Other settings

    // Specify tflite index file should not be compressed for the app apk
    aaptOptions {
        noCompress "tflite"
    }

}

dependencies {
    // Other dependencies

    // Import the Task Vision Library dependency
    implementation 'org.tensorflow:tensorflow-lite-task-vision:0.4.4'
    // Import the GPU delegate plugin Library for GPU inference
    implementation 'org.tensorflow:tensorflow-lite-gpu-delegate-plugin:0.4.4'
}

दूसरा चरण: मॉडल का इस्तेमाल करना

// Initialization
ImageSearcherOptions options =
    ImageSearcherOptions.builder()
        .setBaseOptions(BaseOptions.builder().useGpu().build())
        .setSearcherOptions(
            SearcherOptions.builder().setL2Normalize(true).build())
        .build();
ImageSearcher imageSearcher =
    ImageSearcher.createFromFileAndOptions(context, modelFile, options);

// Run inference
List<NearestNeighbor> results = imageSearcher.search(image);

ज़्यादा जानकारी के लिए, सोर्स कोड और javadoc ImageSearcher को कॉन्फ़िगर करने के ज़्यादा विकल्पों के बारे में जानें.

C++ में अनुमान चलाएं

// Initialization
ImageSearcherOptions options;
options.mutable_base_options()->mutable_model_file()->set_file_name(model_path);
options.mutable_embedding_options()->set_l2_normalize(true);
std::unique_ptr<ImageSearcher> image_searcher = ImageSearcher::CreateFromOptions(options).value();

// Create input frame_buffer from your inputs, `image_data` and `image_dimension`.
// See more information here: tensorflow_lite_support/cc/task/vision/utils/frame_buffer_common_utils.h
std::unique_ptr<FrameBuffer> frame_buffer = CreateFromRgbRawBuffer(
      image_data, image_dimension);

// Run inference
const SearchResult result = image_searcher->Search(*frame_buffer).value();

ज़्यादा जानकारी के लिए, सोर्स कोड ImageSearcher को कॉन्फ़िगर करने के ज़्यादा विकल्पों के बारे में जानें.

Python में इन्फ़रेंस चलाना

पहला चरण: TensorFlow Lite का Pypi पैकेज इंस्टॉल करें.

TensorFlow Lite का सहायता Pypi पैकेज इंस्टॉल करने के लिए, इनका इस्तेमाल करें: आदेश:

pip install tflite-support

दूसरा चरण: मॉडल का इस्तेमाल करना

from tflite_support.task import vision

# Initialization
image_searcher = vision.ImageSearcher.create_from_file(model_path)

# Run inference
image = vision.TensorImage.create_from_file(image_file)
result = image_searcher.search(image)

ज़्यादा जानकारी के लिए, सोर्स कोड ImageSearcher को कॉन्फ़िगर करने के ज़्यादा विकल्पों के बारे में जानें.

परिणामों के उदाहरण

Results:
 Rank#0:
  metadata: burger
  distance: 0.13452
 Rank#1:
  metadata: car
  distance: 1.81935
 Rank#2:
  metadata: bird
  distance: 1.96617
 Rank#3:
  metadata: dog
  distance: 2.05610
 Rank#4:
  metadata: cat
  distance: 2.06347

आसान तरीके आज़माएं ImageSearcher के लिए सीएलआई डेमो टूल की मदद से कैसे डिज़ाइन किया गया है.