-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
87 lines (66 loc) · 2.07 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*-coding:Latin-1 -*
# Extern packages
import numpy
import cv2
import peewee as pw
import json
class JSONField(pw.TextField):
def db_value(self, value):
return json.dumps(value)
def python_value(self, value):
if value is not None:
return json.loads(value)
db = pw.SqliteDatabase("data/image.db")
# Segmentation class and wrapper
segmentationSettings = {
"path": "images/ready_for_segmentation/",
"width": 512,
"height": 512,
"format": ".png",
"color": cv2.IMREAD_GRAYSCALE,
"interpolation": cv2.INTER_AREA,
}
class AlgoSettings(pw.Model):
name = pw.CharField(unique=True)
jsonFile = JSONField(default=None)
class Meta:
database = db
table_name = "AlgoSettings"
# Classification class and wrapper
classificationSettings = {
"path": "images/ready_for_classification/",
"width": 416,
"height": 416,
"format": ".jpg",
"color": cv2.IMREAD_GRAYSCALE,
"interpolation": cv2.INTER_AREA,
}
def initDefaultDB():
db.connect() # Maybe we should test if connection is OK
db.create_tables([AlgoSettings])
# If default models don't exist -> add the row to table
addSettings("segmentation", segmentationSettings)
addSettings("classification", classificationSettings)
db.close()
# Create a new row
def addSettings(seg_name, seg_set):
try:
exist = AlgoSettings.select().where(AlgoSettings.name == seg_name).get()
except AlgoSettings.DoesNotExist:
row = AlgoSettings.create(name=seg_name, jsonFile=seg_set)
row.save()
# Edit an existing row
def editSettings(seg_name, seg_set):
try:
exist = AlgoSettings.select().where(AlgoSettings.name == seg_name).get()
except AlgoSettings.DoesNotExist:
return
query = AlgoSettings.update({AlgoSettings.jsonFile: seg_set}).where(name=seg_name)
query.execute()
# Delete existing row
def deleteSettings(seg_name):
try:
exist = AlgoSettings.select().where(AlgoSettings.name == seg_name).get()
except AlgoSettings.DoesNotExist:
return
exist.delete_instance()