Compare commits
	
		
			4 Commits
		
	
	
		
			master
			...
			x86_bridge
		
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								 | 
						3e5023dcff | |
| 
							
							
								 | 
						8ffdf7fb50 | |
| 
							
							
								 | 
						cff79151d9 | |
| 
							
							
								 | 
						1d5450054f | 
| 
						 | 
					@ -1,16 +1,15 @@
 | 
				
			||||||
FROM nvcr.io/nvidia/l4t-tensorflow:r32.6.1-tf2.5-py3
 | 
					FROM  tensorflow/tensorflow:2.5.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
COPY requirements.txt /app
 | 
					COPY requirements.txt /app
 | 
				
			||||||
RUN pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
 | 
					RUN pip 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"]
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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"]
 | 
					 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
import tensorflow as tf
 | 
					import tensorflow as tf
 | 
				
			||||||
import numpy as np
 | 
					import numpy as np
 | 
				
			||||||
 | 
					import keras.models
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def serve_unet_model():
 | 
					def serve_unet_model():
 | 
				
			||||||
    TFLITE_MODEL = "../app/UNet_25_Crack.tflite"
 | 
					    TFLITE_MODEL = "../app/UNet_25_Crack.tflite"
 | 
				
			||||||
| 
						 | 
					@ -25,3 +25,9 @@ def serve_rcnn_model():
 | 
				
			||||||
            od_graph_def.ParseFromString(serialized_graph)
 | 
					            od_graph_def.ParseFromString(serialized_graph)
 | 
				
			||||||
            tf.import_graph_def(od_graph_def, name='')
 | 
					            tf.import_graph_def(od_graph_def, name='')
 | 
				
			||||||
    return detection_graph
 | 
					    return detection_graph
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def serve_bridge_model():
 | 
				
			||||||
 | 
					    mp = "../app/crack_model.h5"
 | 
				
			||||||
 | 
					    model = keras.models.load_model(mp)
 | 
				
			||||||
 | 
					    return model
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,8 +8,9 @@ from PIL import Image, ImageDraw
 | 
				
			||||||
import tensorflow as tf
 | 
					import tensorflow as tf
 | 
				
			||||||
import ops as utils_ops
 | 
					import ops as utils_ops
 | 
				
			||||||
import visualization_utils as vis_util
 | 
					import visualization_utils as vis_util
 | 
				
			||||||
 | 
					import cv2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from serve import serve_unet_model
 | 
					from serve import serve_unet_model, serve_bridge_model
 | 
				
			||||||
from serve import serve_rcnn_model
 | 
					from serve import serve_rcnn_model
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app = Flask(__name__)
 | 
					app = Flask(__name__)
 | 
				
			||||||
| 
						 | 
					@ -246,5 +247,95 @@ def index():
 | 
				
			||||||
            return jsonify(data)
 | 
					            return jsonify(data)
 | 
				
			||||||
    return "Road Damage Detection"
 | 
					    return "Road Damage Detection"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@app.route("/predict/bridge", methods=["POST"])
 | 
				
			||||||
 | 
					def bridge():
 | 
				
			||||||
 | 
					    if flask.request.method == "POST":
 | 
				
			||||||
 | 
					        if flask.request.files.get("image"):
 | 
				
			||||||
 | 
					            pred_data_colr = []
 | 
				
			||||||
 | 
					            pred_data_inv = []
 | 
				
			||||||
 | 
					            img_src = cv2.imread(flask.request.files["image"], 0)
 | 
				
			||||||
 | 
					            image_dst = resize_keep_aspect_ratio(img_src, (227, 227))
 | 
				
			||||||
 | 
					            bi_inv, colored_img = process_image(image_dst)
 | 
				
			||||||
 | 
					            pred_data_colr.append(colored_img)
 | 
				
			||||||
 | 
					            pred_data_inv.append(bi_inv)
 | 
				
			||||||
 | 
					            final_pred_colr = np.array(pred_data_colr).reshape((len(pred_data_colr), 227, 227, 1))
 | 
				
			||||||
 | 
					            final_pred_inv = np.array(pred_data_inv).reshape((len(pred_data_inv), 227, 227, 1))
 | 
				
			||||||
 | 
					            is_crack = predict_image_util(final_pred_inv)
 | 
				
			||||||
 | 
					            image_np = load_image_into_numpy_array(img_src)
 | 
				
			||||||
 | 
					            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:
 | 
				
			||||||
 | 
					            data = {
 | 
				
			||||||
 | 
					                "code": 10001,
 | 
				
			||||||
 | 
					                "msg": "Could not find image"
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return jsonify(data)
 | 
				
			||||||
 | 
					    return "Bridge Detection"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def predict_image_util(final_pred_inv):
 | 
				
			||||||
 | 
					    model = serve_bridge_model()
 | 
				
			||||||
 | 
					    img_test = (final_pred_inv[0].reshape((1, 227, 227, 1)))
 | 
				
			||||||
 | 
					    raw_predicted_label = model.predict(img_test, batch_size=None, verbose=0, steps=None)[0][0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    predicted_label = 1
 | 
				
			||||||
 | 
					    if raw_predicted_label < 0.8:
 | 
				
			||||||
 | 
					        predicted_label = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    predicted_label_str = 'Crack'
 | 
				
			||||||
 | 
					    if predicted_label == 0:
 | 
				
			||||||
 | 
					        predicted_label_str = 'No Crack'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    print('Raw Predicted Label(Numeric): ' + str(raw_predicted_label))
 | 
				
			||||||
 | 
					    print('Predicted Label : ' + predicted_label_str)
 | 
				
			||||||
 | 
					    return predicted_label
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def process_image(img):
 | 
				
			||||||
 | 
					    ret, bi_inv = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV)
 | 
				
			||||||
 | 
					    return bi_inv, img
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def resize_keep_aspect_ratio(image_src, dst_size):
 | 
				
			||||||
 | 
					    src_h, src_w = image_src.shape[:2]
 | 
				
			||||||
 | 
					    dst_h, dst_w = dst_size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    # 判断应该按哪个边做等比缩放
 | 
				
			||||||
 | 
					    h = dst_w * (float(src_h) / src_w)  # 按照w做等比缩放
 | 
				
			||||||
 | 
					    w = dst_h * (float(src_w) / src_h)  # 按照h做等比缩放
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    h = int(h)
 | 
				
			||||||
 | 
					    w = int(w)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if h <= dst_h:
 | 
				
			||||||
 | 
					        image_dst = cv2.resize(image_src, (dst_w, int(h)))
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        image_dst = cv2.resize(image_src, (int(w), dst_h))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    h_, w_ = image_dst.shape[:2]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    top = int((dst_h - h_) / 2)
 | 
				
			||||||
 | 
					    down = int((dst_h - h_ + 1) / 2)
 | 
				
			||||||
 | 
					    left = int((dst_w - w_) / 2)
 | 
				
			||||||
 | 
					    right = int((dst_w - w_ + 1) / 2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    value = [0, 0, 0]
 | 
				
			||||||
 | 
					    border_type = cv2.BORDER_CONSTANT
 | 
				
			||||||
 | 
					    image_dst = cv2.copyMakeBorder(image_dst, top, down, left, right, border_type, None, value)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return image_dst
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
    app.run()
 | 
					    app.run()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								build.sh
								
								
								
								
							
							
						
						
									
										2
									
								
								build.sh
								
								
								
								
							| 
						 | 
					@ -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 .
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					#/bin/bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,5 +1,7 @@
 | 
				
			||||||
Flask==1.1.2
 | 
					Flask==1.1.2
 | 
				
			||||||
numpy==1.18.4
 | 
					numpy==1.19.5
 | 
				
			||||||
Pillow==7.1.2
 | 
					Pillow==7.1.2
 | 
				
			||||||
six==1.15.0
 | 
					six==1.15.0
 | 
				
			||||||
 | 
					tensorflow==2.5.1
 | 
				
			||||||
 | 
					opencv-contrib-python==4.5.3.56
 | 
				
			||||||
 | 
					opencv-python==4.5.3.56
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue