Compare commits

...

5 Commits

Author SHA1 Message Date
chenxingming 29be050240 修改 dockerfile 2023-04-20 20:24:42 +08:00
chenxingming 793b0c6030 修改接口 2023-04-20 15:34:59 +08:00
chenxingming dacf0bc15a 包名修改 2023-04-20 14:14:16 +08:00
chenxingming ff0c162813 端口调整 2023-04-19 18:05:50 +08:00
chenxingming bc21350a24 桥梁 docker 包 2023-04-19 18:04:55 +08:00
6 changed files with 11 additions and 177 deletions

View File

@ -1,8 +1,8 @@
FROM nvcr.io/nvidia/l4t-tensorflow:r32.6.1-tf2.5-py3 FROM nvcr.io/nvidia/l4t-tensorflow:r32.6.1-tf2.5-py3
RUN apt-get install make g++ gcc RUN apt-get install make g++ gcc
RUN pip3 install gunicorn RUN pip3 install gunicorn
RUN pip3 install setuptools==46.1.3 RUN pip3 install setuptools==46.1.3
#RUN pip3 install flask numpy Pillow six matplotlib
RUN mkdir -p /app RUN mkdir -p /app
WORKDIR /app WORKDIR /app
@ -12,5 +12,3 @@ RUN pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
COPY ./app /app COPY ./app /app
EXPOSE 5000 EXPOSE 5000
CMD ["gunicorn", "--bind", ":5000", "server:app"] CMD ["gunicorn", "--bind", ":5000", "server:app"]

View File

@ -1,18 +0,0 @@
FROM python:3.7.16
ENV PYTHONUNBUFFERED 1
# RUN sed -i s@/deb.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list
# RUN cat /etc/apt/sources.list
# RUN apt-get update \
# && apt-get install -y make \
# && apt-get clean \
# && rm -rf /var/lib/apt/lists/*
RUN mkdir -p /app
WORKDIR /app
COPY requirements.txt /app
RUN python -m venv .
# RUN pip install pip==23.0.1
RUN pip install setuptools==46.1.3
RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
COPY ./app /app
EXPOSE 5000
CMD ["gunicorn", "--bind", ":5000", "server:app"]

View File

@ -1,14 +1,14 @@
# 道路病害检测 # 病害检测
## 利用了cnn网络和unet网络进行道路裂缝和坑洼图片的检测. ## 利用unet网络进行图片的裂缝检测.
## API 接口 ## API 接口
### 道路裂缝检测接口(U-Net CNN) ### 裂缝检测接口(U-Net CNN)
- 请求 - 请求
```curl -k -X POST -F 'image=@image_path/ -v http://0.0.0.0:5000/segment ``` ```curl -k -X POST -F 'image=@image_path/ -v http://0.0.0.0:5000/bridge/crack ```
- 返回接口 - 返回接口
@ -17,41 +17,3 @@
| 返回结果 | result | bool | 是否有裂缝 | | 返回结果 | result | bool | 是否有裂缝 |
| 返回图片 | img | string | 图像的base64编码字符串 | | 返回图片 | img | string | 图像的base64编码字符串 |
### 道路坑洼检测接口(R-CNN)
```curl -k -X POST -F 'image=@image_path/ -v http://0.0.0.0:5000/detect/rcnn ```
- 返回接口
| 名称 | 参数 | 类型 | 说明 |
|------|------|-------|-------|
| 返回结果 | result | bool | 是否有坑洼 |
| 返回图片 | img | string | 图像的base64编码字符串 |
### 裂缝和坑洼检测接口
```curl -k -X POST -F 'image=@image_path/ -v http://0.0.0.0:5000/ ```
- 返回接口
| 名称 | 参数 | 类型 | 说明 |
|------|------|--------|------------------|
| 接口编码 | code | int | 0正常 10001 异常 |
| 原始图片 | img_src | string | 图像的base64编码字符串 |
| 是否有裂缝 | crack | bool | 是否有裂缝 |
| 是否有坑洼 | pothole | bool | 是否有坑洼 |
## 编译说明
### x86编译docker
```docker build -t hpds-road-detection:v1.0 .```
### arm64编译docker
```docker buildx build -t hpds-road-detection-edge:v1.0 . --platform=linux/arm64```

View File

@ -42,45 +42,7 @@ def load_image_into_numpy_array(image):
(im_height, im_width, 3)).astype(np.uint8) (im_height, im_width, 3)).astype(np.uint8)
@app.route("/detect/rcnn", methods=["POST"]) @app.route("/bridge/crack", methods=["POST"])
def detect_rcnn():
if flask.request.method == "POST":
if flask.request.files.get("image"):
image = Image.open(flask.request.files["image"])
image_np = load_image_into_numpy_array(image)
# image_np_expanded = np.expand_dims(image_np, axis=0)
output_dict = run_inference_for_single_image(image_np, detection_graph)
category_index = {0: {"name": "pothole"}, 1: {"name": "pothole"}}
print(output_dict.get('detection_masks'))
i, is_crack = vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
output_dict['detection_boxes'],
output_dict['detection_classes'],
output_dict['detection_scores'],
category_index,
instance_masks=output_dict.get('detection_masks'),
use_normalized_coordinates=True,
line_thickness=8,
skip_scores=True,
skip_labels=True)
img = Image.fromarray(image_np.astype("uint8"))
img = img.resize((128, 128))
raw_bytes = io.BytesIO()
img.save(raw_bytes, "JPEG")
raw_bytes.seek(0)
img_byte = raw_bytes.getvalue()
img_str = base64.b64encode(img_byte)
data = {
"result": is_crack,
"img": img_str.decode('utf-8')
}
return jsonify(data)
else:
return "Could not find image"
return "Please use POST method"
@app.route("/segment", methods=["POST"])
def segment(): def segment():
if flask.request.method == "POST": if flask.request.method == "POST":
if flask.request.files.get("image"): if flask.request.files.get("image"):
@ -176,75 +138,5 @@ def run_inference_for_single_image(image, graph):
return output_dict return output_dict
@app.route('/', methods=["POST"])
def index():
if flask.request.method == "POST":
if flask.request.files.get("image"):
img_src = Image.open(flask.request.files["image"])
# start crack detection
img_segment = prepare_img(img_src, "segment")
input_data = np.expand_dims(img_segment, axis=0)
input_data = np.float32(input_data) / 255.0
tflite_interpreter_c.set_tensor(input_details_c[0]['index'], input_data)
tflite_interpreter_c.invoke()
result = tflite_interpreter_c.get_tensor(output_details_c[0]['index'])
result = result > 0.5
result = result * 255
mask = np.squeeze(result)
bg = np.asarray(img_segment).copy()
is_crack = False
for i in range(len(mask)):
for j in range(len(mask[i])):
if mask[i][j] > 0:
bg[i][j][0] = 0
bg[i][j][1] = 0
bg[i][j][2] = 255
is_crack = True
img = Image.fromarray(bg.astype("uint8"))
# start pothole detection
image_np = load_image_into_numpy_array(img_src)
# image_np_expanded = np.expand_dims(image_np, axis=0)
output_dict = run_inference_for_single_image(image_np, detection_graph)
category_index = {0: {"name": "pothole"}, 1: {"name": "pothole"}}
_, is_pothole = vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
output_dict['detection_boxes'],
output_dict['detection_classes'],
output_dict['detection_scores'],
category_index,
instance_masks=output_dict.get('detection_masks'),
use_normalized_coordinates=True,
line_thickness=8,
skip_scores=True,
skip_labels=True)
raw_bytes = io.BytesIO()
raw_src = io.BytesIO()
img.save(raw_bytes, "JPEG")
img_src.save(raw_src,"JPEG")
raw_bytes.seek(0)
raw_src.seek(0)
img_byte = raw_bytes.getvalue()
img_src_byte = raw_src.getvalue()
img_str = base64.b64encode(img_src_byte)
img_discern = base64.b64encode(img_byte)
data = {
"code": 0,
"crack": is_crack,
"pothole": is_pothole,
"img_src": img_str.decode('utf-8'),
"img_discern": img_discern.decode('utf-8')
}
return jsonify(data)
else:
data = {
"code": 10001,
"msg": "Could not find image"
}
return jsonify(data)
return "Road Damage Detection"
if __name__ == "__main__": if __name__ == "__main__":
app.run() app.run()

View File

@ -1,3 +1,3 @@
# /usr/bash # /usr/bash
docker build --tag hpds-road-detection:1.0.0 . docker build --tag hpds-bridge-detection:1.0.0 .

View File

@ -1,13 +1,13 @@
version: "3.6" version: "3.6"
services: services:
hpds-python-model: hpds-bridge-detection-model:
container_name: hpds-road-detection-model container_name: hpds-bridge-detection-model
image: hpds-road-detection:1.0.0 image: hpds-bridge-detection:1.0.0
networks: networks:
- hpds-network - hpds-network
restart: always restart: always
ports: ports:
- 8000:5000 - "8002:5000"
volumes: volumes:
- /usr/local/cuda/lib64:/usr/local/cuda/lib64 - /usr/local/cuda/lib64:/usr/local/cuda/lib64