Kimang18 commited on
Commit
d806786
·
1 Parent(s): b153448

add object category

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  import shutil
3
  import uuid
4
  import logging
 
5
 
6
  from flask import Flask, redirect, url_for, request, flash, session, after_this_request
7
  from flask import render_template
@@ -19,6 +20,7 @@ app.config["SECRET_KEY"] = '#thaistartsfirst!'
19
  app.config["IMAGES"] = UPLOAD_FOLDER
20
  app.config["OUT"] = OUT_FOLDER
21
  app.config["LABELS"] = []
 
22
  app.config["HEAD"] = 0
23
  app.config["SESSION_PERMANENT"] = False
24
 
@@ -47,7 +49,7 @@ def index():
47
  logger.info(user_id)
48
  anno_path = get_anno_path(user_id)
49
  with open(anno_path, 'w') as f:
50
- f.write("image,id,name,xMin,xMax,yMin,yMax\n")
51
 
52
  if request.method == 'POST':
53
  if 'file' not in request.files:
@@ -93,7 +95,7 @@ def next():
93
  with open(anno_path, 'a+') as f:
94
  for label in app.config["LABELS"]:
95
  f.write(image + "," +
96
- label["id"] + "," +
97
  label["name"] + "," +
98
  str(round(float(label["xMin"]))) + "," +
99
  str(round(float(label["xMax"]))) + "," +
@@ -114,7 +116,7 @@ def add(id):
114
  xMax = request.args.get("xMax")
115
  yMin = request.args.get("yMin")
116
  yMax = request.args.get("yMax")
117
- app.config["LABELS"].append({"id":id, "name":"", "xMin":xMin, "xMax":xMax, "yMin":yMin, "yMax":yMax})
118
  return redirect(url_for('tagger'))
119
 
120
 
@@ -129,8 +131,14 @@ def remove(id):
129
 
130
  @app.route('/label/<id>')
131
  def label(id):
132
- name = request.args.get("name")
133
  app.config["LABELS"][int(id) - 1]["name"] = name
 
 
 
 
 
 
134
  return redirect(url_for('tagger'))
135
 
136
 
@@ -171,4 +179,4 @@ def download():
171
 
172
 
173
  if __name__ == "__main__":
174
- app.run(debug="True")
 
2
  import shutil
3
  import uuid
4
  import logging
5
+ import json
6
 
7
  from flask import Flask, redirect, url_for, request, flash, session, after_this_request
8
  from flask import render_template
 
20
  app.config["IMAGES"] = UPLOAD_FOLDER
21
  app.config["OUT"] = OUT_FOLDER
22
  app.config["LABELS"] = []
23
+ app.config["CATEGORIES"] = {} # []
24
  app.config["HEAD"] = 0
25
  app.config["SESSION_PERMANENT"] = False
26
 
 
49
  logger.info(user_id)
50
  anno_path = get_anno_path(user_id)
51
  with open(anno_path, 'w') as f:
52
+ f.write("image,category,name,xMin,xMax,yMin,yMax\n")
53
 
54
  if request.method == 'POST':
55
  if 'file' not in request.files:
 
95
  with open(anno_path, 'a+') as f:
96
  for label in app.config["LABELS"]:
97
  f.write(image + "," +
98
+ str(label["category"]) + "," +
99
  label["name"] + "," +
100
  str(round(float(label["xMin"]))) + "," +
101
  str(round(float(label["xMax"]))) + "," +
 
116
  xMax = request.args.get("xMax")
117
  yMin = request.args.get("yMin")
118
  yMax = request.args.get("yMax")
119
+ app.config["LABELS"].append({"id":id, "name":"", "category": "", "xMin":xMin, "xMax":xMax, "yMin":yMin, "yMax":yMax})
120
  return redirect(url_for('tagger'))
121
 
122
 
 
131
 
132
  @app.route('/label/<id>')
133
  def label(id):
134
+ name = request.args.get("name").lower()
135
  app.config["LABELS"][int(id) - 1]["name"] = name
136
+ category = app.config["CATEGORIES"].get(name, None)
137
+ if category is None:
138
+ # add to category
139
+ category = len(app.config["CATEGORIES"])
140
+ app.config["CATEGORIES"][name] = category
141
+ app.config["LABELS"][int(id) - 1]["category"] = category
142
  return redirect(url_for('tagger'))
143
 
144
 
 
179
 
180
 
181
  if __name__ == "__main__":
182
+ app.run(debug="True")