-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
84 lines (63 loc) · 2.14 KB
/
model.py
File metadata and controls
84 lines (63 loc) · 2.14 KB
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
import datetime
from typing import Optional
from redis_om.model.model import NotFoundError
from redis_om import (
Field,
HashModel,
Migrator
)
class Dataset(HashModel):
name: str = Field(index=True)
def __repr__(self):
return f"(id={self.pk!r}, name={self.name!r})"
class Image(HashModel):
name: str
image_type: str
path: str = Field(index=True)
dataset_id: str = Field(index=True)
def __repr__(self) -> str:
return f"(id = {self.pk}, name = {self.name}, type = {self.type}, path = {self.path}, dataset_id = {self.dataset_id})"
class RecognitionModel(HashModel):
name: str = Field(index=True)
path: str = Field(index=True)
status: str = Field(index=True)
task_id: Optional[str] = Field(index=True)
created_at: datetime.datetime = Field(index=True, sortable=True)
def __repr__(self) -> str:
return f"(id = {self.pk}, name = {self.name}, path = {self.path}, status = {self.status}, task_id = {self.task_id}), created_at = {self.created_at}"
def findDataset(name):
Migrator().run()
try:
return Dataset.find(Dataset.name == name).first()
except NotFoundError as e:
return None
def findImage(path):
Migrator().run()
try:
return Image.find(Image.path == path).first()
except NotFoundError as e:
return None
def findRecognitionModel(path):
Migrator().run()
try:
return RecognitionModel.find(RecognitionModel.path == path).first()
except NotFoundError as e:
return None
def findRecognitionModelByName(name):
Migrator().run()
try:
return RecognitionModel.find(RecognitionModel.name == name).first()
except NotFoundError as e:
return None
def getLatestModel():
Migrator().run()
try:
return RecognitionModel.find(RecognitionModel.status == 'SUCCESS').sort_by("-created_at").first()
except NotFoundError:
return None
def getDatasetImageTotal(datasetId):
Migrator().run()
return Image.find(Image.dataset_id == datasetId).count()
def getDatasetImages(datasetId):
Migrator().run()
return Image.find(Image.dataset_id == datasetId).all()