-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update big model ram #3062
base: develop
Are you sure you want to change the base?
update big model ram #3062
Changes from 3 commits
965ad40
e973e28
feb4d25
5deb703
e717628
fdbbca6
79fe074
7cb7b5c
8321d03
a906776
ac1eb00
345964a
38be455
ffb5d82
fed21b3
eed2bbf
b54d5de
7433000
0fe4d4e
54b4234
265ee4a
73661e6
131b42c
5aad8fc
c5a7678
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ def __init__(self, func_list, main_indicator="Topk"): | |
def __call__(self, x, image_file=None): | ||
rtn = None | ||
for func in self.func_list: | ||
tmp = func(x, image_file) | ||
tmp = func(*x, image_file) | ||
if type(func).__name__ in self.main_indicator: | ||
rtn = tmp | ||
return rtn | ||
|
@@ -496,3 +496,61 @@ def __call__(self, batch_preds, file_names=None): | |
).astype(np.int8).tolist() | ||
batch_res.append({"attributes": label_res, "output": pred_res}) | ||
return batch_res | ||
|
||
class RamOutPut(object): | ||
|
||
def __init__(self, language="cn",tag_list="", tag_list_chinese="", threshold=0.68, delete_tag_index=[], ram_class_threshold_path="ppcls/utils/RAM/ram_tag_list_threshold.txt"): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 文件需要过一下pre-commit,ram_class_threshold_path在yaml中传入 |
||
self.language = language | ||
assert tag_list, tag_list_chinese | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里需要给出报错信息 |
||
self.tag_list = self.load_tag_list(tag_list) | ||
self.delete_tag_index = delete_tag_index | ||
self.tag_list_chinese = self.load_tag_list(tag_list_chinese) | ||
self.num_class = len(self.tag_list) | ||
self.class_threshold = paddle.ones([self.num_class]) * threshold | ||
ram_class_threshold_path = ram_class_threshold_path | ||
with open(ram_class_threshold_path, "r", encoding="utf-8") as f: | ||
ram_class_threshold = [float(s.strip()) for s in f] | ||
for key,value in enumerate(ram_class_threshold): | ||
self.class_threshold[key] = value | ||
|
||
def load_tag_list(self, tag_list_file): | ||
with open(tag_list_file, "r", encoding="utf-8") as f: | ||
tag_list = f.read().splitlines() | ||
tag_list = np.array(tag_list) | ||
return tag_list | ||
|
||
def __call__(self, logits, bs, file_names=None): | ||
batch_res = [] | ||
logits = paddle.to_tensor(logits) | ||
if bs is None: | ||
if len(logits.shape) <2: | ||
bs = 1 | ||
else: | ||
bs = logits.shape[0] | ||
targets = paddle.where( | ||
F.sigmoid(logits) > self.class_threshold, | ||
paddle.to_tensor([1.0]), | ||
paddle.zeros(self.num_class)) | ||
targets = targets.reshape([bs,-1]) | ||
res = {} | ||
tag = targets.cpu().numpy() | ||
tag[:,self.delete_tag_index] = 0 | ||
tag_output = [] | ||
tag_output_chinese = [] | ||
for b in range(bs): | ||
index = np.argwhere(tag[b] == 1) | ||
token = self.tag_list[index].squeeze(axis=1) | ||
tag_output.append(" | ".join(token)) | ||
token_chinese = self.tag_list_chinese[index].squeeze(axis=1) | ||
tag_output_chinese.append(" | ".join(token_chinese)) | ||
res["cn"] = tag_output_chinese | ||
res["en"] = tag_output | ||
res["all"] = f"en : {tag_output}, cn: {tag_output_chinese}" | ||
|
||
outputformat = { | ||
"class_ids": targets.nonzero(), | ||
"scores": logits, | ||
"label_names": res[self.language] | ||
} | ||
batch_res.append(outputformat) | ||
return outputformat |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import os | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 需要增加版权信息 |
||
|
||
import cv2 | ||
import numpy as np | ||
|
||
from paddleclas.deploy.utils import logger, config | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里不需要从paddleclas下到入吧? |
||
from paddleclas.deploy.utils.get_image_list import get_image_list | ||
from .predict_cls import ClsPredictor | ||
|
||
|
||
def main(config): | ||
cls_predictor = ClsPredictor(config) | ||
image_list = get_image_list(config["Global"]["infer_imgs"]) | ||
|
||
batch_imgs = [] | ||
batch_names = [] | ||
cnt = 0 | ||
for idx, img_path in enumerate(image_list): | ||
img = cv2.imread(img_path) | ||
if img is None: | ||
logger.warning( | ||
"Image file failed to read and has been skipped. The path: {}". | ||
format(img_path)) | ||
else: | ||
img = img[:, :, ::-1] | ||
batch_imgs.append(img) | ||
img_name = os.path.basename(img_path) | ||
batch_names.append(img_name) | ||
cnt += 1 | ||
|
||
if cnt % config["Global"]["batch_size"] == 0 or (idx + 1 | ||
) == len(image_list): | ||
if len(batch_imgs) == 0: | ||
continue | ||
batch_results = cls_predictor.predict(batch_imgs) | ||
for number, result_dict in enumerate(batch_results): | ||
if len(batch_imgs) == 0: | ||
continue | ||
batch_results = cls_predictor.predict(batch_imgs) | ||
for number, result_key in enumerate(batch_results.keys()): | ||
print(f"{img_name}-{result_key}:{batch_results[result_key]}") | ||
batch_imgs = [] | ||
batch_names = [] | ||
if cls_predictor.benchmark: | ||
cls_predictor.auto_logger.report() | ||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
args = config.parse_args() | ||
config = config.get_config(args.config, overrides=args.override, show=True) | ||
main(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改这个的目的是?