Skip to content

Commit

Permalink
Release v1.2.2 (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
PastaTime authored Oct 16, 2020
1 parent b28fedc commit f6c4180
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 10 deletions.
13 changes: 4 additions & 9 deletions client/controller/instance_annotator_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,10 @@ def fetch_class_labels(self, project_id):

# TODO: These labels are project specific and should be editable by the user and stored in the database.

data = [
LabelState(LabelCache.BG_CLASS, [0, 0, 0, 255]),
LabelState("Trunk", [120, 80, 1, 255]),
LabelState("Cane", [150, 250, 1, 255]),
LabelState("Shoot", [1, 130, 200, 255]),
LabelState("Node", [255, 100, 190, 255]),
LabelState("Wire", [255, 128, 1, 255]),
LabelState("Post", [128, 128, 1, 255])
]
data = [LabelState(LabelCache.BG_CLASS, [0, 0, 0, 255])]
resp = utils.get_project_labels(project_id)
for label in resp.json()["labels"]:
data.append(LabelState(label["name"], [label["r"], label["g"], label["b"], 255]))

for label in data:
self.model.labels.add(label.name, label)
Expand Down
6 changes: 6 additions & 0 deletions client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ def get_project_images(project_id, filter_details=None):
return requests.get(url, headers=headers, data=payload)


def get_project_labels(project_id):
url = ClientConfig.SERVER_URL + "projects/" + str(project_id) + "/labels"
headers = {"Accept": "application/json"}
return requests.get(url, headers=headers)


def update_image_meta_by_id(image_id, name=None, lock=None, labeled=None):
image_meta = {}
if name is not None:
Expand Down
18 changes: 18 additions & 0 deletions database/create_database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,21 @@ CREATE TABLE `instance_seg_meta` (
CONSTRAINT `image_fid` FOREIGN KEY (`image_id`) REFERENCES `image` (`image_id`)
) ENGINE=InnoDB AUTO_INCREMENT=137 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Table structure for table `instance_seg_labels`
--

DROP TABLE IF EXISTS `instance_seg_labels`;
CREATE TABLE `instance_seg_labels` (
`label_id` int NOT NULL AUTO_INCREMENT,
`label_name` varchar(45) NOT NULL,
`label_r` int unsigned DEFAULT NULL,
`label_g` int unsigned DEFAULT NULL,
`label_b` int unsigned DEFAULT NULL,
`project_fid` int NOT NULL,
PRIMARY KEY (`label_id`),
UNIQUE KEY `label_name_UNIQUE` (`label_name`),
UNIQUE KEY `label_id_UNIQUE` (`label_id`),
KEY `project_fid_idx` (`project_fid`),
CONSTRAINT `project_label_FKEY` FOREIGN KEY (`project_fid`) REFERENCES `project` (`project_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
96 changes: 95 additions & 1 deletion server/apis/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,24 @@
})

bulk_image_upload = api.model('bulk_image_upload', {
'images': fields.List(fields.Nested(image_upload), required=True)
'images': fields.List(fields.Nested(image_upload), required=True),
})


label = api.model('label', {
'name': fields.String(required=True, description='The label name'),
'r': fields.Integer(required=True, description="The red value of the label"),
'g': fields.Integer(required=True, description="The green value of the label"),
'b': fields.Integer(required=True, description="The blue value of the label")
})

bulk_labels = api.model('bulk_labels', {
'labels': fields.List(fields.Nested(label), required=True)
})




@api.route("")
class ProjectList(Resource):
@api.response(200, "OK", project_bulk)
Expand Down Expand Up @@ -473,3 +487,83 @@ def get(self, pid):
}
code = 500
return marshal(response, api.models['generic_response']), code


@api.route("/<int:pid>/labels")
class ProjectLabelList(Resource):
def get(self, pid):
q_labels = "SELECT label_name, label_r, label_g, label_b from fadb.instance_seg_labels "
q_labels += "WHERE project_fid = %s"

try:
images, _ = db.query(q_labels, (pid,))
labels = []
for row in images:
label = {
"name": row["label_name"],
"r": row["label_r"],
"g": row["label_g"],
"b": row["label_b"]
}
labels.append(label)
code = 200
response = {"labels": labels}
return marshal(response, api.models['bulk_labels']), code
except DatabaseError as e:
response = {
"action": "failed",
"error": {
"code": 500,
"message": e.msg
}
}
code = 500
except BaseException as e:
response = {
"action": "failed",
"error": {
"code": 500,
"message": str(e)
}
}
code = 500
return marshal(response, api.models['generic_response']), code

@api.expect(bulk_labels)
def post(self, pid):
content = request.json["labels"]

q_add_labels = "INSERT INTO instance_seg_labels (project_fid, label_name, label_r, label_g, label_b)"
q_add_labels += "\nVALUES "
q_params = []
for row in content:
q_add_labels += "(%s,%s,%s,%s,%s),"
q_params.extend([pid, row["name"], row["r"], row["g"], row["b"]])
q_add_labels = q_add_labels[:-1]
q_add_labels += ";"

try:
db.query(q_add_labels, q_params)
response = {
"action": "created"
}
code = 201
except DatabaseError as e:
response = {
"action": "failed",
"error": {
"code": 500,
"message": e.msg
}
}
code = 500
except BaseException as e:
response = {
"action": "failed",
"error": {
"code": 500,
"message": str(e)
}
}
code = 500
return marshal(response, api.models['generic_response'], skip_none=True), code

0 comments on commit f6c4180

Please sign in to comment.