Browse Source

Merge pull request '新增benchmark评分类别' (#176) from benchmark-cate into develop

Reviewed-by: 史梦园 <1729788216@qq.com>
tags/v0.1.8
yuyuanshifu 4 years ago
parent
commit
c8d61028c6
7 changed files with 51 additions and 13 deletions
  1. +10
    -0
      models/cloudbrain.go
  2. +1
    -0
      modules/auth/cloudbrain.go
  3. +2
    -0
      modules/setting/setting.go
  4. +11
    -8
      routers/repo/cloudbrain.go
  5. +1
    -1
      templates/base/footer_content.tmpl
  6. +2
    -2
      templates/repo/cloudbrain/index.tmpl
  7. +24
    -2
      templates/repo/cloudbrain/new.tmpl

+ 10
- 0
models/cloudbrain.go View File

@@ -165,6 +165,7 @@ type TaskInfo struct {
Username string `json:"username"`
TaskName string `json:"task_name"`
CodeName string `json:"code_name"`
BenchmarkCategory string `json:"selected_category"`
}

func ConvertToTaskPod(input map[string]interface{}) (TaskPod, error) {
@@ -265,6 +266,15 @@ type ImageInfo struct {
PlaceView string
}

type Categories struct {
Category []*Category `json:"category"`
}

type Category struct {
Id int `json:"id"`
Value string `json:"value"`
}

type CommitImageParams struct {
Ip string `json:"ip"`
TaskContainerId string `json:"taskContainerId"`


+ 1
- 0
modules/auth/cloudbrain.go View File

@@ -11,6 +11,7 @@ type CreateCloudBrainForm struct {
Command string `form:"command" binding:"Required"`
Attachment string `form:"attachment" binding:"Required"`
JobType string `form:"job_type" binding:"Required"`
BenchmarkCategory string `form:"get_benchmark_category"`
}

type CommitImageCloudBrainForm struct {


+ 2
- 0
modules/setting/setting.go View File

@@ -443,6 +443,7 @@ var (
IsBenchmarkEnabled bool
BenchmarkCode string
BenchmarkServerHost string
BenchmarkCategory string

//snn4imagenet config
IsSnn4imagenetEnabled bool
@@ -1150,6 +1151,7 @@ func NewContext() {
IsBenchmarkEnabled = sec.Key("ENABLED").MustBool(false)
BenchmarkCode = sec.Key("BENCHMARKCODE").MustString("https://yangzhx:justfortest123@git.openi.org.cn/yangzhx/detection_benchmark_script.git")
BenchmarkServerHost = sec.Key("HOST").MustString("http://192.168.202.90:3366/")
BenchmarkCategory = sec.Key("CATEGORY").MustString("")

sec = Cfg.Section("snn4imagenet")
IsSnn4imagenetEnabled = sec.Key("ENABLED").MustBool(false)


+ 11
- 8
routers/repo/cloudbrain.go View File

@@ -108,7 +108,6 @@ func CloudBrainNew(ctx *context.Context) {
}

for i, payload := range resultPublic.Payload.ImageInfo {
log.Info(resultPublic.Payload.ImageInfo[i].Place)
if strings.HasPrefix(resultPublic.Payload.ImageInfo[i].Place, "192.168") {
resultPublic.Payload.ImageInfo[i].PlaceView = payload.Place[strings.Index(payload.Place, "/"):len(payload.Place)]
} else {
@@ -131,6 +130,10 @@ func CloudBrainNew(ctx *context.Context) {
ctx.Data["model_path"] = cloudbrain.ModelMountPath
ctx.Data["benchmark_path"] = cloudbrain.BenchMarkMountPath
ctx.Data["is_benchmark_enabled"] = setting.IsBenchmarkEnabled

var categories *models.Categories
json.Unmarshal([]byte(setting.BenchmarkCategory), &categories)
ctx.Data["benchmark_categories"] = categories.Category
ctx.Data["snn4imagenet_path"] = cloudbrain.Snn4imagenetMountPath
ctx.Data["is_snn4imagenet_enabled"] = setting.IsSnn4imagenetEnabled
ctx.HTML(200, tplCloudBrainNew)
@@ -162,12 +165,12 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) {

benchmarkPath := setting.JobPath + jobName + cloudbrain.BenchMarkMountPath
if setting.IsBenchmarkEnabled && jobType == string(models.JobTypeBenchmark) {
downloadRateCode(repo, jobName, setting.BenchmarkCode, benchmarkPath)
downloadRateCode(repo, jobName, setting.BenchmarkCode, benchmarkPath, form.BenchmarkCategory)
}

snn4imagenetPath := setting.JobPath + jobName + cloudbrain.Snn4imagenetMountPath
if setting.IsSnn4imagenetEnabled && jobType == string(models.JobTypeSnn4imagenet) {
downloadRateCode(repo, jobName, setting.Snn4imagenetCode, snn4imagenetPath)
downloadRateCode(repo, jobName, setting.Snn4imagenetCode, snn4imagenetPath, "")
}

err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType)
@@ -258,16 +261,15 @@ func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrain

func CloudBrainStop(ctx *context.Context) {
var jobID = ctx.Params(":jobid")
log.Info(jobID)
task, err := models.GetCloudbrainByJobID(jobID)
if err != nil {
ctx.ServerError("GetCloudbrainByJobID failed", err)
return
}

if task.Status != string(models.JobRunning) {
log.Error("the job(%s) is not running", task.JobName)
ctx.ServerError("the job is not running", errors.New("the job is not running"))
if task.Status == string(models.JobStopped) {
log.Error("the job(%s) has been stopped", task.JobName)
ctx.ServerError("the job has been stopped", errors.New("the job has been stopped"))
return
}

@@ -337,7 +339,7 @@ func downloadCode(repo *models.Repository, codePath string) error {
return nil
}

func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath string) error {
func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath, benchmarkCategory string) error {
err := os.MkdirAll(codePath, os.ModePerm)
if err != nil {
log.Error("mkdir codePath failed", err.Error())
@@ -366,6 +368,7 @@ func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath strin
Username: repo.Owner.Name,
TaskName: taskName,
CodeName: repo.Name,
BenchmarkCategory: benchmarkCategory,
})
if err != nil {
log.Error("json.Marshal failed", err.Error())


+ 1
- 1
templates/base/footer_content.tmpl View File

@@ -33,7 +33,7 @@
<div class="sixteen wide mobile eight wide tablet eight wide computer column" style=" margin:2.0rem 0">
{{.i18n.Tr "custom.foot.copyright"}} <a href="http://beian.miit.gov.cn/" target="_blank">京ICP备18004880号-2</a>
<br>
{{.i18n.Tr "powered_by 鹏城实验室云脑、"}}<a href="https://www.trustie.net/" target="_blank">Trustie确实</a>{{.i18n.Tr "、gitea"}}
{{.i18n.Tr "powered_by 鹏城实验室云脑、"}}<a href="https://www.trustie.net/" target="_blank">Trustie确实</a>{{.i18n.Tr "、gitea"}}
<br>
</div>
</div>


+ 2
- 2
templates/repo/cloudbrain/index.tmpl View File

@@ -297,9 +297,9 @@
<!-- 停止 -->
<div class="one wide column">
<div class="ui text center clipboard">
<form id="stopForm-{{.JobID}}" action="{{if ne .Status "RUNNING"}}javascript:void(0){{else}}{{$.Link}}/{{.JobID}}/stop{{end}}" method="post">
<form id="stopForm-{{.JobID}}" action="{{if eq .Status "STOPPED"}}javascript:void(0){{else}}{{$.Link}}/{{.JobID}}/stop{{end}}" method="post">
{{$.CsrfTokenHtml}}
<a class="fitted" onclick="document.getElementById('stopForm-{{.JobID}}').submit();" style="{{if ne .Status "RUNNING"}}color:#CCCCCC{{end}}; font-size:16px; font-weight:bold">停止</a>
<a class="fitted" onclick="document.getElementById('stopForm-{{.JobID}}').submit();" style="{{if eq .Status "STOPPED"}}color:#CCCCCC{{end}}; font-size:16px; font-weight:bold">停止</a>
</form>
</div>
</div>


+ 24
- 2
templates/repo/cloudbrain/new.tmpl View File

@@ -110,7 +110,6 @@
{{.i18n.Tr "repo.cloudbrain.new"}}
</h3>
<div class="ui attached segment">
<!-- <br> -->
<div class="inline required field">
<label>任务名称</label>
<input name="job_name" id="cloudbrain_job_name" placeholder="任务名称" value="{{.job_name}}" tabindex="3" autofocus required maxlength="255">
@@ -125,6 +124,17 @@
</select>
</div>

<div class="inline required field cloudbrain_benchmark">
<label style="vertical-align: top; margin-top:9px">数据集类别</label>
<select class="ui search dropdown" multiple="multiple" id="cloudbrain_benchmark_category" style='width:385px'>
{{range .benchmark_categories}}
<option value="{{.Value}}">{{.Value}}</option>
{{end}}
</select>
</div>

<input id="store_category" type="hidden" name="get_benchmark_category">

<div class="inline required field">
<label>镜像</label>
<select class="ui search dropdown" id="cloudbrain_image" placeholder="选择镜像" style='width:385px' name="image">
@@ -170,6 +180,7 @@
<label>启动命令</label>
<textarea name="command" rows="10" readonly="readonly">{{.command}}</textarea>
</div>

<div class="inline field">
<label></label>
<button class="ui green button" onclick="showmask()">
@@ -196,7 +207,12 @@
document.getElementById("mask").style.display = "none"
}
}

$('#cloudbrain_benchmark_category')
.dropdown({
placeholder: "选择数据集类别",
})
$('select.dropdown')
.dropdown();

@@ -212,4 +228,10 @@
}
})
})

$('.ui.green.button').click(function() {
selected_value = $("#cloudbrain_benchmark_category").val()
$('#store_category').attr("value", selected_value)
})

</script>

Loading…
Cancel
Save