Skip to content

Commit e0ab74d

Browse files
committed
revise model
1 parent 15522ff commit e0ab74d

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

detect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from numpy import random
1414
import json
1515

16-
def detect(source, trace=False, weights='model_weights/best.pt', img_size=512, conf_thres=0.5, iou_thres=0.5, agnostic_nms= False, is_augment=False, class_filter=None):
16+
def detect(source, trace=False, weights='model_weights/best.pt', img_size=512, conf_thres=0.4, iou_thres=0.5, agnostic_nms= False, is_augment=False, class_filter=None):
1717
# Initialize
1818
set_logging()
1919
device = select_device('')

main.py

+28-7
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,18 @@ def loginHandler():
7777
user = userCollection.find_one({ "email" : username})
7878
print(user.keys())
7979
if "location" in user.keys():
80+
8081
print(user["location"])
81-
location = locationCollection.find_one({"id" : int(user["location"])})
82+
#location = locationCollection.find_one({"id" : int(user["location"])})
83+
location = user["location"]
8284
if "name" in user.keys():
8385
name = user["name"]
8486

8587
isPasswordCorrect = bcrypt.checkpw(password.encode(), user["password"])
8688
# print(isPasswordCorrect)
8789
print(user)
8890
if isPasswordCorrect:
89-
accessToken = create_access_token(identity={"username" : username, "role" : "user", "name":name})
91+
accessToken = create_access_token(identity={"username" : username, "role" : "user", "name":name, "location" : location}, expires_delta=datetime.timedelta(days=365))
9092
return {"result" : {
9193
"access_token" : accessToken
9294
}}
@@ -164,7 +166,19 @@ def detect():
164166

165167
access_token = None
166168
result = load_image_and_detect(base64Image, filters)
167-
if auth:
169+
print(type(result))
170+
result = json.loads(result)
171+
temp = result["object_detected"]
172+
highest = 0
173+
highest_obj= None
174+
for i in temp:
175+
if i['confidence']>highest:
176+
highest= i['confidence']
177+
highest_obj= i
178+
179+
180+
181+
if auth and result["status"] != "failed":
168182
access_token = auth.split(" ")[1]
169183
decoded = decode_token(access_token)
170184
historiesCollection = clientDB["histories"]
@@ -176,7 +190,7 @@ def detect():
176190
"detected_at" : current_time,
177191
"location" : decoded["sub"]["location"],
178192
"name" : decoded["sub"]["name"],
179-
"detection_result" : result
193+
"detection_result" : highest_obj
180194
})
181195

182196

@@ -193,7 +207,7 @@ def getDetectionHistory():
193207
histories = list(histories)
194208
results = []
195209
for hist in histories:
196-
results.append({"username" : hist["username"], "image" : hist["image"], "detected_at" : hist["detected_at"], "location" : hist["location"], "name" : hist["name"], "detection_result" : json.loads(hist["detection_result"])})
210+
results.append({"username" : hist["username"], "image" : hist["image"], "detected_at" : hist["detected_at"], "location" : hist["location"], "name" : hist["name"], "detection_result" : hist["detection_result"]})
197211
return make_response({"result":{"histories" : results}}, 200)
198212

199213

@@ -210,16 +224,23 @@ def getUserProfile():
210224
user = clientDB["users"].find_one({"email" : decoded["sub"]["username"]})
211225
if "location" in user.keys():
212226
location = user["location"]
227+
location = clientDB["locations"].find_one({"id" : location})
228+
if not location:
229+
location = None
213230
if "name" in user.keys():
214231
name = user["name"]
215232

216-
return make_response({
233+
try:
234+
return make_response({
217235
"result" : {
218236
"username" : decoded["sub"]["username"],
219-
"location" : location,
237+
"location" : location["id"],
220238
"name" : name
221239
}
222240
})
241+
except Exception as E:
242+
print(E)
243+
return make_response({"result" : {"username" : decoded["sub"]["username"], "location_name":None, "location_image" : None, "location_id" : None, "name" : name}}, 200)
223244

224245
@app.route("/upload-file", methods=["POST"])
225246
@jwt_required()

model_weights/best.pt

24.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)