[wip][vec] update client, test=doc #1543

pull/1547/head
qingen 4 years ago
parent 08f3db5b70
commit 100998dec9

@ -87,8 +87,8 @@ Then to start the system server, and it provides HTTP backend services.
2022-03-07 17:39:14,865 INFO on.py startup 45 Waiting for application startup.
INFO: Application startup complete.
2022-03-07 17:39:14,866 INFO on.py startup 59 Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8002 (Press CTRL+C to quit)
2022-03-07 17:39:14,867 INFO server.py _log_started_message 206 Uvicorn running on http://127.0.0.1:8002 (Press CTRL+C to quit)
INFO: Uvicorn running on http://0.0.0.0:8002 (Press CTRL+C to quit)
2022-03-07 17:39:14,867 INFO server.py _log_started_message 206 Uvicorn running on http://0.0.0.0:8002 (Press CTRL+C to quit)
```
### 3. Usage
@ -124,7 +124,10 @@ Then to start the system server, and it provides HTTP backend services.
```
- GUI test (optional)
Navigate to 127.0.0.1:8068 in your browser to access the front-end interface.
Navigate to 127.0.0.1:8068 in your browser to access the front-end interface
Note: If the browser and the service are not on the same machine, then the IP needs to be changed to the IP of the machine where the service is located, and the corresponding API_URL in docker-comemater. yaml needs to be changed and the service can be restarted
- Insert data
Download the data and decompress it to a path named /home/speech/data. Then enter /home/speech/data in the address bar of the upload page to upload the data

@ -89,8 +89,8 @@ ffce340b3790 minio/minio:RELEASE.2020-12-03T00-03-10Z "/usr/bin/docker-ent…"
2022-03-07 17:39:14,865 INFO on.py startup 45 Waiting for application startup.
INFO: Application startup complete.
2022-03-07 17:39:14,866 INFO on.py startup 59 Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8002 (Press CTRL+C to quit)
2022-03-07 17:39:14,867 INFO server.py _log_started_message 206 Uvicorn running on http://127.0.0.1:8002 (Press CTRL+C to quit)
INFO: Uvicorn running on http://0.0.0.0:8002 (Press CTRL+C to quit)
2022-03-07 17:39:14,867 INFO server.py _log_started_message 206 Uvicorn running on http://0.0.0.0:8002 (Press CTRL+C to quit)
```
### 3. 测试方法
@ -127,6 +127,9 @@ ffce340b3790 minio/minio:RELEASE.2020-12-03T00-03-10Z "/usr/bin/docker-ent…"
- 前端测试(可选)
在浏览器中输入 127.0.0.1:8068 访问前端页面
注:如果浏览器和服务不在同一台机器上,那么 IP需要修改成服务所在的机器 IP并且docker-compose.yaml 中相应的 API_URL 也要修改,并重新起服务即可
- 上传音频
下载数据并解压到一文件夹,假设为 /home/speech/data那么在上传页面地址栏输入 /home/speech/data 进行数据上传

@ -64,7 +64,7 @@ services:
webclient:
container_name: audio-webclient
image: iregistry.baidu-int.com/paddlespeech/audio-search-client:1.0
image: iregistry.baidu-int.com/paddlespeech/audio-search-client:2.3
networks:
app_net:
ipv4_address: 172.16.23.13

@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import librosa
import numpy as np
from logs import LOGGER
@ -27,7 +29,7 @@ def get_audio_embedding(path):
# TODO add infer/python interface to get embedding, now fake it by rand
# vpr = ECAPATDNN(checkpoint_path=None, device='cuda')
# embedding = vpr.inference(audio)
np.random.seed(hash(os.path.basename(path)) % 1000000)
embedding = np.random.rand(1, 2048)
embedding = embedding / np.linalg.norm(embedding)
embedding = embedding.tolist()[0]

@ -104,11 +104,12 @@ async def search_audio(request: Request,
_, paths, distances = do_search(host, table_name, query_audio_path,
MILVUS_CLI, MYSQL_CLI)
names = []
for i in paths:
names.append(os.path.basename(i))
for path, score in zip(paths, distances):
names.append(os.path.basename(path))
LOGGER.info(f"search result {path}, score {score}")
res = dict(zip(paths, zip(names, distances)))
# Sort results by distance metric, closest distances first
res = sorted(res.items(), key=lambda item: item[1][1])
res = sorted(res.items(), key=lambda item: item[1][1], reverse=True)
LOGGER.info("Successfully searched similar audio!")
return res
except Exception as e:
@ -126,12 +127,12 @@ async def search_local_audio(request: Request,
_, paths, distances = do_search(host, table_name, query_audio_path,
MILVUS_CLI, MYSQL_CLI)
names = []
for path, dist in zip(paths, distances):
for path, score in zip(paths, distances):
names.append(os.path.basename(path))
LOGGER.info(f"search result {path}, distance {dist}")
LOGGER.info(f"search result {path}, score {score}")
res = dict(zip(paths, zip(names, distances)))
# Sort results by distance metric, closest distances first
res = sorted(res.items(), key=lambda item: item[1][1])
res = sorted(res.items(), key=lambda item: item[1][1], reverse=True)
LOGGER.info("Successfully searched similar audio!")
return res
except Exception as e:
@ -164,4 +165,4 @@ async def drop_tables(table_name: str=None):
if __name__ == '__main__':
uvicorn.run(app=app, host='127.0.0.1', port=8002)
uvicorn.run(app=app, host='0.0.0.0', port=8002)

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
sys.path.append("..")
from config import DEFAULT_TABLE
from logs import LOGGER

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
sys.path.append("..")
from config import DEFAULT_TABLE
from logs import LOGGER

@ -16,9 +16,9 @@ import sys
from diskcache import Cache
from encode import get_audio_embedding
from ..config import DEFAULT_TABLE
from ..logs import LOGGER
sys.path.append("..")
from config import DEFAULT_TABLE
from logs import LOGGER
def get_audios(path):

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
sys.path.append("..")
from config import DEFAULT_TABLE
from config import TOP_K
from encode import get_audio_embedding
@ -34,6 +34,7 @@ def do_search(host, table_name, audio_path, milvus_cli, mysql_cli):
for i in range(len(paths)):
tmp = "http://" + str(host) + "/data?audio_path=" + str(paths[i])
paths[i] = tmp
distances[i] = (1 - distances[i]) * 100
return vids, paths, distances
except Exception as e:
LOGGER.error(f"Error with search: {e}")

Loading…
Cancel
Save