Adding Losing function
This commit is contained in:
parent
3ba341b415
commit
0198015475
9 changed files with 91 additions and 5 deletions
21
YOLO/Dockerfiles/app/Dockerfile
Executable file
21
YOLO/Dockerfiles/app/Dockerfile
Executable file
|
@ -0,0 +1,21 @@
|
|||
FROM python:3.7
|
||||
|
||||
RUN mkdir /code
|
||||
WORKDIR /code
|
||||
|
||||
ADD entrypoint.sh /code/entrypoint.sh
|
||||
ADD requirements.txt /code/requirements.txt
|
||||
ADD app/ /code
|
||||
|
||||
RUN ls
|
||||
#RUN pip install -r requirements.txt --no-cache-dir
|
||||
#RUN apt-get install apt-transport-https
|
||||
RUN apt update -y
|
||||
RUN apt install python3-pip -y
|
||||
|
||||
#RUN pip3 install --default-timeout=100 -r requirements.txt
|
||||
|
||||
EXPOSE 50002
|
||||
ENV FLASK_APP "/code/app.py"
|
||||
CMD ["/code/entrypoint.sh"]
|
||||
|
25
YOLO/Dockerfiles/app/app/app.py
Normal file
25
YOLO/Dockerfiles/app/app/app.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# app/__init__.py
|
||||
|
||||
from flask import Flask
|
||||
import requests
|
||||
import json
|
||||
import sys
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/update/<string:id>/<string:attr>/<int:value>/')
|
||||
def update(id,attr,value):
|
||||
import update_grid;
|
||||
path = "/Datasets/grids/"# PATH TO VOLUME
|
||||
r = requests.get("http://127.0.0.1:50011/update/"+id+"/"+attr+"/"+str(value)+"/")
|
||||
print("Message",file=sys.stdout)
|
||||
print(r,file=sys.stdout)
|
||||
dict = r.json()
|
||||
# TO DO
|
||||
# GET COORDINATES x and y
|
||||
nb_img = dict["Nb"]
|
||||
for x,y in dict["img"]:
|
||||
update_grid.hide_image(path+id+".png", path+id+".png", float(x),float(y))
|
||||
return str(nb_img)
|
||||
|
||||
return app
|
16
YOLO/Dockerfiles/app/app/update_grid.py
Normal file
16
YOLO/Dockerfiles/app/app/update_grid.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
""" UPDATE GRID """
|
||||
import cv2
|
||||
import os
|
||||
|
||||
# Path image : chemin vers la grille d'images de célébrités
|
||||
# Output image : chemin vers la grille avec l'image cachée
|
||||
# x,y : coordonées (x,y) de la sortie yolo (qui correspond au centre de l'image)
|
||||
|
||||
def hide_image(path_img, output_img, x, y):
|
||||
img = cv2.imread(path_img)
|
||||
x1 = int((x-0.1)*890)
|
||||
y1 = int((y-0.1)*1090)
|
||||
x2 = int((x+0.1)*890)
|
||||
y2 = int((y+0.1)*1090)
|
||||
cv2.rectangle(img, ( x1 , y1), ( x2, y2), (255, 255, 255), -1)
|
||||
cv2.imwrite(output_img, img)
|
13
YOLO/Dockerfiles/app/entrypoint.sh
Executable file
13
YOLO/Dockerfiles/app/entrypoint.sh
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/bin/sh
|
||||
|
||||
sleep 5
|
||||
|
||||
pip3 install -U Flask
|
||||
pip3 install Flask-RESTful
|
||||
pip3 install opencv-python
|
||||
pip3 install opencv-contrib-python
|
||||
pip3 install opencv-python-headless
|
||||
pip3 install opencv-contrib-python-headless
|
||||
|
||||
flask run --host=0.0.0.0 --port=50008
|
||||
|
1
YOLO/Dockerfiles/app/requirements.txt
Normal file
1
YOLO/Dockerfiles/app/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Flask==1.1.1
|
4
YOLO/Dockerfiles/docker_run.sh
Executable file
4
YOLO/Dockerfiles/docker_run.sh
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
docker build -t image_YOLO Dockerfiles/app
|
||||
docker run -it --network="host" -v /home/user/Bureau/Datasets:/Datasets image_YOLO:latest
|
2
YOLO/command_line.sh
Executable file
2
YOLO/command_line.sh
Executable file
|
@ -0,0 +1,2 @@
|
|||
Dockerfiles/docker_run.sh
|
||||
|
|
@ -16,13 +16,17 @@ def create_app():
|
|||
def get_question(id=1):
|
||||
with sql.connect("/Datasets/database/database.db") as con:
|
||||
cur = con.cursor()
|
||||
row = cur.execute("select * from questions where id=\'"+str(id)+"\';")
|
||||
return(row.fetchone()[2])
|
||||
row = cur.execute("select * from questions where id=\'"+str(id)+"\';").fetchone()
|
||||
dico=dict()
|
||||
dico["attribut"]=row[1]
|
||||
dico["intitule"]=row[2]
|
||||
dico["response"]=row[3]
|
||||
return(json.dumps(dico))
|
||||
|
||||
@app.route('/create/<string:token>/')
|
||||
def create(token='TEST'):
|
||||
with sql.connect("/Datasets/database/database.db") as con:
|
||||
data=pd.read_csv("/Datasets/database/"+token+".csv",delimiter=";")
|
||||
data=pd.read_csv("/Datasets/database/"+token+".csv",delimiter=",")
|
||||
data.to_sql(token,con,if_exists='replace',index=False)
|
||||
return '1'
|
||||
|
||||
|
@ -30,14 +34,14 @@ def create_app():
|
|||
def update(token,attr,value):
|
||||
with sql.connect("/Datasets/database/database.db") as con:
|
||||
cur = con.cursor()
|
||||
sql_update= "update " + token + " set excluded = 1 where "+attr+"="+str(value)+";"
|
||||
sql_update= "update " + token + " set Excluded = 1 where "+attr+"="+str(value)+";"
|
||||
cur.execute(sql_update)
|
||||
cur.execute("select x,y from "+token+" where "+attr+"=\'"+str(value)+"\';")
|
||||
rows = cur.fetchall()
|
||||
dico = dict()
|
||||
dico["img"]=rows
|
||||
cur = con.cursor()
|
||||
cur.execute("SELECT COUNT(*) FROM "+token+" where excluded = 0")
|
||||
cur.execute("SELECT COUNT(*) FROM "+token+" where Excluded = 0")
|
||||
dico["Nb"]=cur.fetchone()[0]
|
||||
return(json.dumps(dico))
|
||||
return app
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue