Skip to content

jhs2jhs/Alibaba-Cloud-Image-Search-Demo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alibaba Cloud Image Search Demo

Introduction

This demo workshop showcases the Image Search API, an Alibaba Cloud service to search products by uploading a photo.

The demo is a website compatible with desktop computers and smartphones. It contains two main pages:

  • A management page where a user can creates/updates/deletes products in the database.
  • A search page that lets users to find products that look similar to an uploaded photo. The picture can come from a JPEG file or directly from a camera when the user views this page on a smartphone.

Change the default category

By default Image Search use 88888888 category which is OTHERS. If you plan to use other category you have to manually recompile it and change the code.

Link to the categories

In order to change the default category you need to edit one file called ImageSearchServiceImpl.java at line 95 from request.setCatId(category.getId()); to request.setCatId(category.DIGITAL_DEVICES.getId());

Line 162 from // request.setCatId(ObjectCategory.FURNITURE.getId());

to request.setCatId(ObjectCategory.DIGITAL_DEVICES.getId());

or any needed category ID.

Category ID Description
0 TOPS
1 DRESSES
2 BOTTOMS
3 BAGS
4 SHOES
5 ACCESSORIES
6 SNACKS
7 MAKEUP
8 BOTTLE_DRINKS
9 FURNITURE
20 TOYS
21 UNDERWEARS
22 DIGITAL_DEVICES
88888888 OTHERS

Compile the code on macOS

I am using macOS Mojave and brew to install maven. The installation is very simple and works out of the box.

  1. Install brew on macOS Brew on macOS
  2. Install maven using brew:
brew update
brew install maven      
brew cleanup  
  1. Install rpm using brew
brew install rpm
  1. Once installed you can proceed with the build.

Build

Clone the project, open a terminal and type:

mvn clean install

This generates the fat JAR "target/web-image-search-engine.jar".

If you plan to install this demo on a RPM-based Linux distribution, you can type the following command:

mvn rpm:rpm

This generates the package "target/rpm/web-image-search-engine/RPMS/noarch/web-image-search-engine-*.noarch.rpm".

The RPM contains the fat JAR and a Systemd script. It allows users to easily execute the server when the machine starts. It also automatically restarts the application after a crash.

Installation and execution

If you just want to run the fat JAR, open a terminal and run:

java -jar web-image-search-engine-latest.jar

This starts the server on the port 8080 and outputs the logs in the console.

RPM based Linux distribution Installation

If you are using a RPM-based Linux distribution, such as CentOS 7.4+, you can install the RPM with the following commands:

yum -y update
yum -y install web-image-search-engine-latest.noarch.rpm

You can start the server with the following command:

systemctl start web-image-search-engine.service

You can check the logs by running the following command:

journalctl --unit=web-image-search-engine

The server should start and listen to the port 8080. If you prefer to use the port 80, you can setup a reverse proxy such as Nginx.

If you want to automatically run the server when the machine starts, enter the following command:

systemctl enable web-image-search-engine.service

Demo configuration

Image Search instance creation

Before running the application, you first need to create a "Product Search instance":

  • Go to https://www.alibabacloud.com/, login (or create an account) and go to the web console.
  • Obtain an accessKeyId and an accessKeySecret (in the web console, click on your user picture on the top-right of the page and select "AccessKey").
  • Create an Product Search instance (search type = "Product Search").
  • If you want, create an ECS instance with CentOS 7.4.

Open your web browser on the following URL: http://your_server_address:8080/

Image Search demo configuration

If this is the first time you use the application, you will be redirected to the configuration page.

Image Search empty page

  1. Enter Administrator password twice to protect configuration page.
  2. Provide AccessKeyID.
  3. Provide AccessKeySecret.
  4. As region ID enter the Image Search instance region. For example if Image Search instance is created in Singapore the Region ID will be ap-southeast-1.
    If you don't know the regionID you can check all regionID's Alibaba Cloud Region ID.
  5. Enter your Image Search instance name.
  6. Enter product search instance domain. Similiar to regionID your Image Search instance domain will be: imagesearch.regionID.aliyuncs.com.
  7. If you wish you can enter product search instance namespace. This might help you to distinguish different images in the same Image Search instance.

Image Search admin page configured

Once configured, using this web application is pretty straightforward:

  1. Go to the "Manage objects" page: it displays all the sample products registered in the database. You can add, modify and delete objects.
  2. Go back to the "Home" page and upload an image. If have added enough objects, you should always see 20 results with various scores.

After many searches you will find that the results are not always meaningful. For example you will get 20 results even if you search with a picture of an object that doesn't exist in the database (in fact, the value "20" is hardcoded in the demo source code). This is a limitation of this API, and there is no simple solution. The absolute value of the score doesn't help (unless you search with the exact same picture as a registered object), only its relative value can be used for sorting results.

Pre-compiled rpms:

Ready to copy&paste CentOS commands to execute install

TOPS

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-tops.noarch.rpm
yum -y install web-image-search-engine-tops.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

DRESSES

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-dresses.noarch.rpm
yum -y install web-image-search-engine-dresses.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

BOTTOMS

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-bottoms.noarch.rpm
yum -y install web-image-search-engine-bottoms.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

BAGS

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-bags.noarch.rpm
yum -y install web-image-search-engine-bags.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

SHOES

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-shoes.noarch.rpm
yum -y install web-image-search-engine-shoes.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

ACCESSORIES

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-accessories.noarch.rpm
yum -y install web-image-search-engine-accessories.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

SNACKS

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-snacks.noarch.rpm
yum -y install web-image-search-engine-snacks.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

MAKEUP

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-makeup.noarch.rpm
yum -y install web-image-search-engine-makeup.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

BOTTLE_DRINKS

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-bottle-drinks.noarch.rpm
yum -y install web-image-search-engine-bottle-drinks.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

FURNITURE

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-furniture.noarch.rpm
yum -y install web-image-search-engine-furniture.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

TOYS

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-toys.noarch.rpm
yum -y install web-image-search-engine-toys.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

UNDERWEARS

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-underwears.noarch.rpm
yum -y install web-image-search-engine-underwears.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

DIGITAL_DEVICES

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-digital-devices.noarch.rpm
yum -y install web-image-search-engine-digital-devices.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

OTHERS

yum -y update
wget https://imagesearchrpm.oss-ap-southeast-1.aliyuncs.com/web-image-search-engine-others.noarch.rpm
yum -y install web-image-search-engine-others.noarch.rpm
systemctl start web-image-search-engine.service
systemctl enable web-image-search-engine.service

There are few solutions for this problem:

  • Have a huge database of images, like Taobao.
  • Teach the Image Search API to recognize bad results.
    For example if the customer only sells furniture, then non-furniture objects should also be registered in the database and marked as "BAD", like this the program can filter the Image Search results by removing the BAD objects.

Thanks

This application uses the following libraries/frameworks/tools:

About

image-search-workshop

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 51.0%
  • JavaScript 35.9%
  • HTML 8.9%
  • CSS 4.0%
  • Shell 0.2%