提交 100998de 编写于 作者: Q qingen

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

上级 08f3db5b
...@@ -87,8 +87,8 @@ Then to start the system server, and it provides HTTP backend services. ...@@ -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. 2022-03-07 17:39:14,865 | INFO | on.py | startup | 45 | Waiting for application startup.
INFO: Application startup complete. INFO: Application startup complete.
2022-03-07 17:39:14,866 | INFO | on.py | startup | 59 | 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) 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://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://0.0.0.0:8002 (Press CTRL+C to quit)
``` ```
### 3. Usage ### 3. Usage
...@@ -124,7 +124,10 @@ Then to start the system server, and it provides HTTP backend services. ...@@ -124,7 +124,10 @@ Then to start the system server, and it provides HTTP backend services.
``` ```
- GUI test (optional) - 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 - 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 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…" ...@@ -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. 2022-03-07 17:39:14,865 | INFO | on.py | startup | 45 | Waiting for application startup.
INFO: Application startup complete. INFO: Application startup complete.
2022-03-07 17:39:14,866 | INFO | on.py | startup | 59 | 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) 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://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://0.0.0.0:8002 (Press CTRL+C to quit)
``` ```
### 3. 测试方法 ### 3. 测试方法
...@@ -127,6 +127,9 @@ ffce340b3790 minio/minio:RELEASE.2020-12-03T00-03-10Z "/usr/bin/docker-ent…" ...@@ -127,6 +127,9 @@ ffce340b3790 minio/minio:RELEASE.2020-12-03T00-03-10Z "/usr/bin/docker-ent…"
- 前端测试(可选) - 前端测试(可选)
在浏览器中输入 127.0.0.1:8068 访问前端页面 在浏览器中输入 127.0.0.1:8068 访问前端页面
注:如果浏览器和服务不在同一台机器上,那么 IP需要修改成服务所在的机器 IP,并且docker-compose.yaml 中相应的 API_URL 也要修改,并重新起服务即可
- 上传音频 - 上传音频
下载数据并解压到一文件夹,假设为 /home/speech/data,那么在上传页面地址栏输入 /home/speech/data 进行数据上传 下载数据并解压到一文件夹,假设为 /home/speech/data,那么在上传页面地址栏输入 /home/speech/data 进行数据上传
......
...@@ -64,7 +64,7 @@ services: ...@@ -64,7 +64,7 @@ services:
webclient: webclient:
container_name: audio-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: networks:
app_net: app_net:
ipv4_address: 172.16.23.13 ipv4_address: 172.16.23.13
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import os
import librosa import librosa
import numpy as np import numpy as np
from logs import LOGGER from logs import LOGGER
...@@ -27,7 +29,7 @@ def get_audio_embedding(path): ...@@ -27,7 +29,7 @@ def get_audio_embedding(path):
# TODO add infer/python interface to get embedding, now fake it by rand # TODO add infer/python interface to get embedding, now fake it by rand
# vpr = ECAPATDNN(checkpoint_path=None, device='cuda') # vpr = ECAPATDNN(checkpoint_path=None, device='cuda')
# embedding = vpr.inference(audio) # embedding = vpr.inference(audio)
np.random.seed(hash(os.path.basename(path)) % 1000000)
embedding = np.random.rand(1, 2048) embedding = np.random.rand(1, 2048)
embedding = embedding / np.linalg.norm(embedding) embedding = embedding / np.linalg.norm(embedding)
embedding = embedding.tolist()[0] embedding = embedding.tolist()[0]
......
...@@ -104,11 +104,12 @@ async def search_audio(request: Request, ...@@ -104,11 +104,12 @@ async def search_audio(request: Request,
_, paths, distances = do_search(host, table_name, query_audio_path, _, paths, distances = do_search(host, table_name, query_audio_path,
MILVUS_CLI, MYSQL_CLI) MILVUS_CLI, MYSQL_CLI)
names = [] names = []
for i in paths: for path, score in zip(paths, distances):
names.append(os.path.basename(i)) names.append(os.path.basename(path))
LOGGER.info(f"search result {path}, score {score}")
res = dict(zip(paths, zip(names, distances))) res = dict(zip(paths, zip(names, distances)))
# Sort results by distance metric, closest distances first # 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!") LOGGER.info("Successfully searched similar audio!")
return res return res
except Exception as e: except Exception as e:
...@@ -126,12 +127,12 @@ async def search_local_audio(request: Request, ...@@ -126,12 +127,12 @@ async def search_local_audio(request: Request,
_, paths, distances = do_search(host, table_name, query_audio_path, _, paths, distances = do_search(host, table_name, query_audio_path,
MILVUS_CLI, MYSQL_CLI) MILVUS_CLI, MYSQL_CLI)
names = [] names = []
for path, dist in zip(paths, distances): for path, score in zip(paths, distances):
names.append(os.path.basename(path)) 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))) res = dict(zip(paths, zip(names, distances)))
# Sort results by distance metric, closest distances first # 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!") LOGGER.info("Successfully searched similar audio!")
return res return res
except Exception as e: except Exception as e:
...@@ -164,4 +165,4 @@ async def drop_tables(table_name: str=None): ...@@ -164,4 +165,4 @@ async def drop_tables(table_name: str=None):
if __name__ == '__main__': 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 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import sys import sys
sys.path.append("..")
from config import DEFAULT_TABLE from config import DEFAULT_TABLE
from logs import LOGGER from logs import LOGGER
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import sys import sys
sys.path.append("..")
from config import DEFAULT_TABLE from config import DEFAULT_TABLE
from logs import LOGGER from logs import LOGGER
......
...@@ -16,9 +16,9 @@ import sys ...@@ -16,9 +16,9 @@ import sys
from diskcache import Cache from diskcache import Cache
from encode import get_audio_embedding from encode import get_audio_embedding
sys.path.append("..")
from ..config import DEFAULT_TABLE from config import DEFAULT_TABLE
from ..logs import LOGGER from logs import LOGGER
def get_audios(path): def get_audios(path):
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import sys import sys
sys.path.append("..")
from config import DEFAULT_TABLE from config import DEFAULT_TABLE
from config import TOP_K from config import TOP_K
from encode import get_audio_embedding from encode import get_audio_embedding
...@@ -34,6 +34,7 @@ def do_search(host, table_name, audio_path, milvus_cli, mysql_cli): ...@@ -34,6 +34,7 @@ def do_search(host, table_name, audio_path, milvus_cli, mysql_cli):
for i in range(len(paths)): for i in range(len(paths)):
tmp = "http://" + str(host) + "/data?audio_path=" + str(paths[i]) tmp = "http://" + str(host) + "/data?audio_path=" + str(paths[i])
paths[i] = tmp paths[i] = tmp
distances[i] = (1 - distances[i]) * 100
return vids, paths, distances return vids, paths, distances
except Exception as e: except Exception as e:
LOGGER.error(f"Error with search: {e}") LOGGER.error(f"Error with search: {e}")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册