Skip to content

Commit

Permalink
Merge pull request #243 from kookmin-sw/feature/226
Browse files Browse the repository at this point in the history
Feat : 지도 기능 추가
  • Loading branch information
ancy0 authored May 19, 2024
2 parents c54b7f2 + 8afd0a4 commit 06b1631
Show file tree
Hide file tree
Showing 42 changed files with 1,258 additions and 621 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ aiServer/runs/detect/exp/2021-08-05 13-11-50 .jpg
/aiServer/TextReID/runs
aiServer/crowdhuman_yolov5m.pt
ai/.env
frontend/.env
frontend/.env
server/src/main/java/com/capstone/server/dataInitializer/CCTVInitializer.java

Binary file removed ai/TextReID/datasets/cuhkpedes/clip_vocab_vit.npy
Binary file not shown.
4 changes: 0 additions & 4 deletions ai/TextReID/lib/data/datasets/__init__.py

This file was deleted.

23 changes: 0 additions & 23 deletions ai/TextReID/lib/data/datasets/concat_dataset.py

This file was deleted.

70 changes: 0 additions & 70 deletions ai/TextReID/lib/data/datasets/cuhkpedes.py

This file was deleted.

148 changes: 74 additions & 74 deletions ai/TextReID/lib/data/encode/encoding.py
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
import json
import re
import os


word_dict = {} # word (str) : encode (int)
max_onehot = -1 # 없는 단어를 새로 딕셔너리에 추가할 때 필요


def load_word_dict(file_path):
global word_dict
global max_onehot

if os.path.exists(file_path):
with open(file_path, "r") as file:
data = json.load(file)
word_dict = data["word_dict"]
max_onehot = data["max_onehot"]
else:
word_dict_path = os.path.dirname(os.path.abspath(__file__))+"/word_dict/test.json"
update_word_dict(word_dict_path)


def save_word_dict(file_path):
global word_dict
global max_onehot

data = {"word_dict": word_dict, "max_onehot": max_onehot}

with open(file_path, "w") as file:
json.dump(data, file)


def update_word_dict(file_path):
global word_dict
global max_onehot

with open(file_path, "r") as file:
data = json.load(file)

for i in range(len(data["annotations"])):
words = re.sub(r'[^a-zA-Z0-9\s]', '', data["annotations"][i]["sentence"])
words = words.split()
for word, onehot in zip(words, data["annotations"][i]["onehot"]):
if onehot > max_onehot:
max_onehot = onehot
if word.lower() not in word_dict.keys():
word_dict[word.lower()] = onehot


def encode(query):
global word_dict
global max_onehot

output = []
query = re.sub(r'[^a-zA-Z0-9\s]', ' ', query)

for w in query.split():
try:
output.append(word_dict[w.lower()])
except KeyError:
print("Key %s not found in the dictionary." % w)
word_dict[w.lower()] = max_onehot + 1
output.append(word_dict[w.lower()])
max_onehot += 1

return output


def encoder(caption, file_path=os.path.dirname(os.path.abspath(__file__))+"/word_dict/annotations.json"):
load_word_dict(file_path)
caption = encode(caption)
save_word_dict(file_path)

import json
import re
import os


word_dict = {} # word (str) : encode (int)
max_onehot = -1 # 없는 단어를 새로 딕셔너리에 추가할 때 필요


def load_word_dict(file_path):
global word_dict
global max_onehot

if os.path.exists(file_path):
with open(file_path, "r") as file:
data = json.load(file)
word_dict = data["word_dict"]
max_onehot = data["max_onehot"]
else:
word_dict_path = os.path.dirname(os.path.abspath(__file__))+"/word_dict/test.json"
update_word_dict(word_dict_path)


def save_word_dict(file_path):
global word_dict
global max_onehot

data = {"word_dict": word_dict, "max_onehot": max_onehot}

with open(file_path, "w") as file:
json.dump(data, file)


def update_word_dict(file_path):
global word_dict
global max_onehot

with open(file_path, "r") as file:
data = json.load(file)

for i in range(len(data["annotations"])):
words = re.sub(r'[^a-zA-Z0-9\s]', '', data["annotations"][i]["sentence"])
words = words.split()
for word, onehot in zip(words, data["annotations"][i]["onehot"]):
if onehot > max_onehot:
max_onehot = onehot
if word.lower() not in word_dict.keys():
word_dict[word.lower()] = onehot


def encode(query):
global word_dict
global max_onehot

output = []
query = re.sub(r'[^a-zA-Z0-9\s]', ' ', query)

for w in query.split():
try:
output.append(word_dict[w.lower()])
except KeyError:
print("Key %s not found in the dictionary." % w)
word_dict[w.lower()] = max_onehot + 1
output.append(word_dict[w.lower()])
max_onehot += 1

return output


def encoder(caption, file_path=os.path.dirname(os.path.abspath(__file__))+"/word_dict/annotations.json"):
load_word_dict(file_path)
caption = encode(caption)
save_word_dict(file_path)

return caption
Loading

0 comments on commit 06b1631

Please sign in to comment.