算法调用改动重新提交
parent
a811ec3566
commit
45532b78e8
|
|
@ -2586,14 +2586,51 @@ namespace OpenAuth.App.ServiceApp
|
|||
.Where(x => x.Id == req.AlgoInstanceId)
|
||||
.ToListAsync();
|
||||
var tagsIds = algoInstances.Select(x => x.Tags).ToList();
|
||||
// todo 关于存在多个算法的处理
|
||||
// todo 关于存在多个算法的处理 查询多个算法
|
||||
var algoIds = algoInstances.First().AlgoIds.Split(",").ToArray();
|
||||
var algo = await db
|
||||
var algos = await db
|
||||
.Queryable<LasaAlgorithmsRepository>()
|
||||
.Where(x => x.Id == algoIds[0])
|
||||
.FirstAsync();
|
||||
dynamic json = new
|
||||
ExpandoObject();
|
||||
.Where(x => algoIds.Contains(x.Id)).ToListAsync();
|
||||
//创建多模型数据结构
|
||||
var models = new List<ModelConfig>();
|
||||
foreach (var algo in algos)
|
||||
{
|
||||
// 当前算法对应的 tag
|
||||
var algoInstance = algoInstances.First(a => a.AlgoIds.Contains(algo.Id));
|
||||
|
||||
var tagIds = algoInstance.Tags.Split(",", StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
var labels = await db.Queryable<LasaModelLabel>()
|
||||
.Where(l => tagIds.Contains(l.Id) && l.PId == algo.Id)
|
||||
.ToListAsync();
|
||||
|
||||
Dictionary<string, ModelTag> tags = new Dictionary<string, ModelTag>();
|
||||
|
||||
foreach (var label in labels)
|
||||
{
|
||||
tags[label.EnumValue.ToString()] = new ModelTag
|
||||
{
|
||||
name = label.Name,
|
||||
reliability = label.Reliability,
|
||||
select = true,
|
||||
color = label.Color
|
||||
};
|
||||
}
|
||||
|
||||
var model = new ModelConfig
|
||||
{
|
||||
path = algo.Path,
|
||||
encryption_key = algo.SecretKey,
|
||||
tags = tags,
|
||||
conf_thres = algo.ConfThres,
|
||||
imgsz = algo.Imgsz,
|
||||
device = "cuda:0",
|
||||
line_width = 2,
|
||||
enabled = algo.Enable
|
||||
};
|
||||
|
||||
models.Add(model);
|
||||
}
|
||||
var x = SnowFlakeSingle.instance;
|
||||
//var pushUrl = $"rtmp://box.wisestcity.com:1935/live/{x.NextId()}";
|
||||
var config = ConfigHelper.GetConfigRoot();
|
||||
|
|
@ -2616,17 +2653,14 @@ namespace OpenAuth.App.ServiceApp
|
|||
{
|
||||
pushUrl += req.UavSn + 1;
|
||||
}
|
||||
|
||||
json.rtmp_url = req.RtmpUrl; // 无人机直播流
|
||||
json.push_url = pushUrl; // 识别结果推流
|
||||
json.imgsz = 640;
|
||||
json.frame_skip = 1;
|
||||
json.model_name = algo.Path;
|
||||
//json.model_name = "yolo12x.pt";
|
||||
json.taskname = task.TaskName;
|
||||
json.taskid = req.TaskId;
|
||||
// 算法id
|
||||
json.AlgoId = algo.Id;
|
||||
var reqBody = new StartDetectionResp
|
||||
{
|
||||
rtmp_url = req.RtmpUrl,
|
||||
push_url = pushUrl,
|
||||
taskname = task.TaskName,
|
||||
taskid = req.TaskId,
|
||||
models = models
|
||||
};
|
||||
var taskRecord = new LasaTask()
|
||||
{
|
||||
Id = req.TaskId,
|
||||
|
|
@ -2634,35 +2668,28 @@ namespace OpenAuth.App.ServiceApp
|
|||
PushUrl = pushUrl,
|
||||
AIInspection = "true",
|
||||
};
|
||||
var tagIdArray = new List<string>();
|
||||
foreach (var tagId in tagsIds)
|
||||
{
|
||||
tagIdArray.AddRange(tagId.Split(",").ToList());
|
||||
}
|
||||
|
||||
await db.Updateable(taskRecord).IgnoreNullColumns().ExecuteCommandAsync();
|
||||
var tag = await db
|
||||
.Queryable<LasaModelLabel>()
|
||||
.Where(l => tagIdArray.Contains(l.Id))
|
||||
.ToArrayAsync();
|
||||
IDictionary<string, object> jsonTag = new Dictionary<string, object>();
|
||||
foreach (var lasaModelLabel in tag)
|
||||
{
|
||||
var model = new
|
||||
{
|
||||
name = lasaModelLabel.Name,
|
||||
reliability = lasaModelLabel.Reliability
|
||||
};
|
||||
jsonTag[lasaModelLabel.EnumValue.ToString()] = model;
|
||||
}
|
||||
|
||||
json.tag = jsonTag;
|
||||
_logger.LogDebug($"发送的json:{JsonConvert.SerializeObject(json)}");
|
||||
var content = new StringContent(JsonConvert.SerializeObject(json), Encoding.UTF8, "application/json");
|
||||
_logger.LogDebug($"发送的json:{JsonConvert.SerializeObject(reqBody)}");
|
||||
var content = new StringContent(JsonConvert.SerializeObject(reqBody), Encoding.UTF8, "application/json");
|
||||
var url = config["AIModelApi:Url"];
|
||||
using var httpClient = new HttpClient();
|
||||
var response = await httpClient.PostAsync($"{url}/start_detection", content);
|
||||
var response = await httpClient.PostAsync($"{url}/api/tasks/creat", content);
|
||||
//var response = await httpClient.PostAsync("http://192.168.10.131:9025/start_detection", content);
|
||||
if (response.IsSuccessStatusCode)//低一哦成功记录当前任务数据
|
||||
{
|
||||
var responseStr = await response.Content.ReadAsStringAsync();
|
||||
var root = JsonNode.Parse(responseStr)?.AsObject();
|
||||
var taskId = root?["data"]?["task_id"]?.ToString();
|
||||
if (!string.IsNullOrEmpty(taskId))
|
||||
{
|
||||
_redisCacheContext.HashSetAsync($"ai:task:{taskId}", new[]{
|
||||
new HashEntry("TaskId", taskId),
|
||||
new HashEntry("Status", "running"),
|
||||
new HashEntry("CreateTime", DateTime.Now.ToString("O"))
|
||||
});
|
||||
}
|
||||
}
|
||||
_logger.LogDebug($"成功调用{response.IsSuccessStatusCode}");
|
||||
db.Ado.CommitTran();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue