Skip to content
Snippets Groups Projects
Commit 0fef4029 authored by Danial Hezarkhani's avatar Danial Hezarkhani
Browse files

detr_hpc updated

parent 3ca6849d
No related branches found
No related tags found
1 merge request!12Detr hpc merge to main
......@@ -17,22 +17,20 @@ ENV LOG_EVERY_N_STEP 5
ENV MAX_NU_METRIC_IMAGES 10
ENV DETECTION_THRESHOLD 0.8
ENV GRPCPORT 8061
ENV HTTPPORT 8062
WORKDIR /home/objectdetection
#RUN pip install --no-cache-dir jupyter
COPY od ./od
COPY __init__.py logger.py main.py config.py model_pb2_grpc.py model_pb2.py model.proto detr_server.py detr_client_test.py ./
COPY cat1.png ./
COPY app.py ./
COPY static ./static
COPY templates ./templates
#EXPOSE 8061 8062
ENTRYPOINT [ "python","main.py" ]
#ENTRYPOINT jupyter notebook --ip=0.0.0.0 --port=8062 --allow-root --NotebookApp.token=''
#python /home/objectdetection/main.py -gp 8061 -hp 8062 -f /p/home/jusers/hezarkhani1/juwels/testrun1 -d /p/home/jusers/hezarkhani1/judac/shared/maritimair
from flask import Flask, render_template, redirect, url_for, session, request
from flask import Flask, render_template, redirect, url_for, session, request,Response
from werkzeug.datastructures import MultiDict
from flask_bootstrap import Bootstrap
from flask_wtf import FlaskForm
......@@ -8,13 +8,20 @@ from collections import namedtuple
import os
import json
import copy
import datetime, time
import model_pb2
import model_pb2_grpc
import grpc
from logger import Logger
logger = Logger(__name__)
config = None
port = int(os.getenv("HTTPPORT", "8062"))
httpport = None
grpcport = None
#port = int(os.getenv("HTTPPORT", "8062"))
app = Flask(__name__)
......@@ -87,6 +94,25 @@ class TrainingStatusForm(FlaskForm):
TrainingStatus = StringField('Training status will be displayed here. Please save the parameters first before observing the status.', render_kw={'readonly': True})
Get = SubmitField('Get Status')
@app.route("/start_traing", methods=['POST'])
def start_train():
logger.debug("Calling HPP_Stub for training")
addr = 'localhost:{}'.format(grpcport)
logger.debug("connecting to {}".format(addr))
with grpc.insecure_channel(addr) as channel:
stub = model_pb2_grpc.DetrModelServicerStub(channel)
ui_request = model_pb2.TrainingConfig()
ui_request.config = "test"
response = stub.startTraining(ui_request)
logger.debug("Training finished")
print(response)
return redirect('/')
@app.route('/', methods=['GET', 'POST'])
def training_input():
......@@ -127,11 +153,21 @@ def training_input():
return render_template("index.html", training_var_form=training_vals_form, trainingStatusForm=trainingStatusForm, current_para=current_para)
def app_run(config_main):
# @app.route('/log')
# def progress_log():
# def generate():
# for line in Pygtail(LOG_FILE, every_n=1):
# yield "data:" + str(line) + "\n\n"
# time.sleep(0.5)
# return Response(generate(), mimetype= 'text/event-stream')
def app_run(config_main,http_port_input,grpc_port_input):
global config
global grpcport
grpcport = grpc_port_input
config = config_main
app.secret_key = "detr"
bootstrap = Bootstrap(app)
app.run(host="0.0.0.0", port=port)
app.run(host="0.0.0.0", port=http_port_input)
#app_run()
\ No newline at end of file
import os
class Config:
def __init__(self, PROD_FLAG, SHARED_FOLDER):
def __init__(self, PROD_FLAG, SHARED_FOLDER, dataset_path = None):
self.PROD_FLAG = PROD_FLAG
self.SHARED_FOLDER = SHARED_FOLDER
......@@ -34,7 +34,10 @@ class Config:
self.TENSORBOARD_FOLDER = os.getenv(self.lightning_logs_dir, "./detr/dev/tensorboard_logs")
self.create_not_existing_dirs(([SHARED_FOLDER,self.custom_model_path,self.dataset_path,self.lightning_logs_dir,self.input_path,self.output_path,self.status_folder]))
self.create_not_existing_dirs([SHARED_FOLDER,self.custom_model_path,self.dataset_path,self.lightning_logs_dir,self.input_path,self.output_path,self.status_folder])
if dataset_path:
self.dataset_path = dataset_path
def create_not_existing_dirs(self, list_of_paths):
......
......@@ -41,14 +41,10 @@ def start_train():
with grpc.insecure_channel(addr) as channel:
stub = model_pb2_grpc.DetrModelServicerStub(channel)
#inference
ui_request = model_pb2.TrainingConfig()
ui_request.config = "test"
response = stub.startTraining(ui_request)
# training
# ui_request = model_pb2.TrainingConfig(config="test")
# response = stub.startTraining(ui_request)
logger.debug("Training finished")
......
......@@ -9,7 +9,7 @@ import threading
from od.detrOD import DetrOD
from config import Config
from app import app_run, get_train_parameters
from app import get_train_parameters
from logger import Logger
logger = Logger(__name__)
......@@ -160,18 +160,10 @@ class DetrModelServicer(model_pb2_grpc.DetrModelServicer):
context.set_code(grpc.StatusCode.NOT_FOUND)
def serve_grpc(config):
def serve_grpc(config,port):
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
model_pb2_grpc.add_DetrModelServicerServicer_to_server(DetrModelServicer(config), server)
server.add_insecure_port('[::]:{}'.format(port))
server.start()
logger.info("Start config web-ui")
return server
if __name__ == '__main__':
prod_flag = os.getenv("PRODUCTION", False)
config = Config(prod_flag, SHARED_FOLDER)
grpc_server = serve_grpc(config)
threading.Thread(target=app_run(config)).start()
grpc_server.wait_for_termination()
\ No newline at end of file
return server
\ No newline at end of file
......@@ -2,20 +2,27 @@ from od.detrOD import DetrOD
import os
from config import Config
import detr_server
from app import app_run
import argparse
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('-i','--input', type=str , help='Input Image',required=True) # will be accesible with args.OPT
parser.add_argument('-o','--output', type=str , help='Output Image',required=True) # will be accesible with args.OPT
parser.add_argument('-f','--folder', type=str , help='Path for files directory',required=True) # will be accesible with args.OPT
args = parser.parse_args()
import threading
if __name__ == '__main__':
folder_path = args.folder
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('-gp','--grpc-port', type=int , help='grpc port',required=True)
parser.add_argument('-hp','--http-port', type=int , help='http port',required=True)
parser.add_argument('-f','--folder', type=str , help='Folder path',required=True)
parser.add_argument('-d','--dataset-path', type=str , help='Dataset path',required=True)
args = parser.parse_args()
# run_inference(args.input, args.output)
prod_flag = os.getenv("PRODUCTION", False)
config = Config(prod_flag,folder_path)
detr_server.serve(config)
config = Config(prod_flag, args.folder, args.dataset_path)
grpc_server = detr_server.serve_grpc(config, args.grpc_port)
#threading.Thread(target=app_run(config,args.http_port,args.grpc_port)).start()
threading.Thread(target=app_run, args=(config, args.http_port, args.grpc_port)).start()
grpc_server.wait_for_termination()
# detrOd = DetrOD(config)
# input_image = args.input
......
......@@ -70,10 +70,10 @@ class DetrOD():
dataloader_workers:int = 0
):
logger.info("Training batch size is {}".format(batch_size))
logger.info("Using databasee under this path for training: {}".format(self.config.dataset_path))
logger.info("Trained model will be saved in this path: {}".format(self.config.custom_model_path))
dataprovider = DataProvider(extractor=self.extractor,
dataset_path=self.config.dataset_path,
annotation_file_name=self.config.annotation_file_name,
......@@ -131,6 +131,7 @@ class DetrOD():
def get_metrics(self,threshold=0.7):
logger.info("Getting metrics with current threshhold of: {}".format(threshold))
preds = []
target = []
......
$(document).ready(function(){
$('#startBtn').click(function(){
console.log("submit recieved")
$.ajax({
type: 'POST',
url: '/start_traing',
contentType: 'application/json',
success: function(response){
console.log(response);
alert(response.message);
},
error: function(xhr, status, error){
console.error(error);
alert('An error occurred while sending the request.');
}
});
});
});
\ No newline at end of file
......@@ -16,9 +16,8 @@
<div class="card-body">
{{ render_form(training_var_form) }}
</div>
</div>
</div>
<div class="col-6 mb-4">
<div class="card shadow mb-4">
......@@ -38,9 +37,25 @@
<textarea class="form-control" style="height:100%;">{{ current_para }}</textarea>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 mb-4">
<div class="card shadow mb-4">
<div class="card-body">
<button type="button" id="startBtn" class="btn btn-warning btn-block">Start Training</button>
</div>
</div>
</div>
</div>
</div>
......@@ -54,5 +69,6 @@
<!-- Custom scripts for all pages-->
<script src="static/js/sb-admin-2.min.js"></script>
<script src="static/js/scripts.js"></script>
</body>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment