From 07dddac0f741cba5afff2b904b1334097b587f5e Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Wed, 10 Mar 2021 16:26:15 +0800 Subject: [PATCH 1/3] add snn4imagenet --- custom/conf/app.ini.sample | 5 +++++ models/cloudbrain.go | 1 + modules/cloudbrain/cloudbrain.go | 10 +++++++++- modules/setting/setting.go | 10 ++++++++++ routers/repo/cloudbrain.go | 21 +++++++++++++-------- routers/routes/routes.go | 1 - templates/repo/cloudbrain/new.tmpl | 1 + 7 files changed, 39 insertions(+), 10 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index a027624f4..350889a3f 100755 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -1061,6 +1061,11 @@ ENABLED = true BENCHMARKCODE = https://yangzhx:justfortest123@git.openi.org.cn/yangzhx/detection_benchmark_script.git HOST = http://192.168.202.90:3366/ +[snn4imagenet] +ENABLED = true +SNN4IMAGENETCODE = https://yult:eh2Ten4iLYjFkbj@git.openi.org.cn/ylt/snn4imagenet.git +HOST = http://192.168.202.90:3366/ + [decompress] HOST = http://192.168.207.34:39987 USER = cW4cMtH24eoWPE7X diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 036c25264..9784a58b5 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -25,6 +25,7 @@ const ( JobTypeDebug JobType = "DEBUG" JobTypeBenchmark JobType = "BENCHMARK" + JobTypeSnn4imagenet JobType = "SNN4IMAGENET" ModelArtsCreateQueue ModelArtsJobStatus = "CREATE_QUEUING" //免费资源创建排队中 ModelArtsCreating ModelArtsJobStatus = "CREATING" //创建中 diff --git a/modules/cloudbrain/cloudbrain.go b/modules/cloudbrain/cloudbrain.go index 50de926ca..551353bd5 100755 --- a/modules/cloudbrain/cloudbrain.go +++ b/modules/cloudbrain/cloudbrain.go @@ -15,6 +15,7 @@ const ( DataSetMountPath = "/dataset" ModelMountPath = "/model" BenchMarkMountPath = "/benchmark" + Snn4imagenetMountPath = "/snn4imagenet" TaskInfoName = "/taskInfo" SubTaskName = "task1" @@ -22,7 +23,7 @@ const ( Success = "S000" ) -func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, jobType string) error { +func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType string) error { dataActualPath := setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + "/" + setting.Attachment.Minio.BasePath + @@ -78,6 +79,13 @@ func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, ReadOnly: true, }, }, + { + HostPath: models.StHostPath{ + Path: snn4imagenetPath, + MountPath: Snn4imagenetMountPath, + ReadOnly: true, + }, + }, }, }) if err != nil { diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 3e71804ab..65fddc7a0 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -444,6 +444,11 @@ var ( BenchmarkCode string BenchmarkServerHost string + //snn4imagenet config + IsSnn4imagenetEnabled bool + Snn4imagenetCode string + Snn4imagenetServerHost string + //blockchain config BlockChainHost string CommitValidDate string @@ -1146,6 +1151,11 @@ func NewContext() { 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/") + sec = Cfg.Section("snn4imagenet") + IsSnn4imagenetEnabled = sec.Key("ENABLED").MustBool(false) + Snn4imagenetCode = sec.Key("SNN4IMAGENETCODE").MustString("https://yangzhx:justfortest123@git.openi.org.cn/yangzhx/detection_benchmark_script.git") + Snn4imagenetServerHost = sec.Key("HOST").MustString("http://192.168.202.90:3366/") + sec = Cfg.Section("blockchain") BlockChainHost = sec.Key("HOST").MustString("http://192.168.136.66:3302/") CommitValidDate = sec.Key("COMMIT_VALID_DATE").MustString("2021-01-15") diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index d0e662505..e4b30c7b4 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -143,7 +143,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { jobType := form.JobType codePath := setting.JobPath + jobName + cloudbrain.CodeMountPath - if jobType != string(models.JobTypeBenchmark) && jobType != string(models.JobTypeDebug) { + if jobType != string(models.JobTypeBenchmark) && jobType != string(models.JobTypeDebug) && jobType != string(models.JobTypeSnn4imagenet){ log.Error("jobtype error:", jobType) ctx.RenderWithErr("jobtype error", tplCloudBrainNew, &form) return @@ -160,10 +160,15 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { benchmarkPath := setting.JobPath + jobName + cloudbrain.BenchMarkMountPath if setting.IsBenchmarkEnabled && jobType == string(models.JobTypeBenchmark) { - downloadBenchmarkCode(repo, jobName, benchmarkPath) + downloadRateCode(repo, jobName, setting.BenchmarkCode, benchmarkPath) } - err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, jobType) + snn4imagenetPath := setting.JobPath + jobName + cloudbrain.Snn4imagenetMountPath + if setting.IsSnn4imagenetEnabled && jobType == string(models.JobTypeSnn4imagenet) { + downloadRateCode(repo, jobName, setting.Snn4imagenetCode, snn4imagenetPath) + } + + err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, jobType) if err != nil { ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) return @@ -324,14 +329,14 @@ func downloadCode(repo *models.Repository, codePath string) error { return nil } -func downloadBenchmarkCode(repo *models.Repository, taskName string, benchmarkPath string) error { - err := os.MkdirAll(benchmarkPath, os.ModePerm) +func downloadRateCode(repo *models.Repository, taskName, gitPath, codePath string) error { + err := os.MkdirAll(codePath, os.ModePerm) if err != nil { - log.Error("mkdir benchmarkPath failed", err.Error()) + log.Error("mkdir codePath failed", err.Error()) return err } - command := "git clone " + setting.BenchmarkCode + " " + benchmarkPath + command := "git clone " + gitPath + " " + codePath cmd := exec.Command("/bin/bash", "-c", command) output, err := cmd.Output() log.Info(string(output)) @@ -340,7 +345,7 @@ func downloadBenchmarkCode(repo *models.Repository, taskName string, benchmarkPa return err } - fileName := benchmarkPath + cloudbrain.TaskInfoName + fileName := codePath + cloudbrain.TaskInfoName f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm) if err != nil { log.Error("OpenFile failed", err.Error()) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index adc8938a9..1e8dba06f 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -529,7 +529,6 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/get_multipart_url", repo.GetMultipartUploadUrl) m.Post("/complete_multipart", repo.CompleteMultipart) m.Post("/update_chunk", repo.UpdateMultipart) - m.Get("/get_obs_key", repo.GetObsKey) }, reqSignIn) m.Group("/attachments", func() { diff --git a/templates/repo/cloudbrain/new.tmpl b/templates/repo/cloudbrain/new.tmpl index b21264772..b72556678 100755 --- a/templates/repo/cloudbrain/new.tmpl +++ b/templates/repo/cloudbrain/new.tmpl @@ -117,6 +117,7 @@ From 518ebf60d915cb29903325fcd9dd2ce2ff6eb248 Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Thu, 11 Mar 2021 16:39:25 +0800 Subject: [PATCH 2/3] JobTypeSnn4imagenet --- routers/repo/cloudbrain.go | 19 +++++++++++++++++++ routers/routes/routes.go | 1 + templates/repo/cloudbrain/index.tmpl | 2 +- templates/repo/cloudbrain/new.tmpl | 13 ++++++++++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index e4b30c7b4..b7160d325 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -131,6 +131,8 @@ func CloudBrainNew(ctx *context.Context) { ctx.Data["model_path"] = cloudbrain.ModelMountPath ctx.Data["benchmark_path"] = cloudbrain.BenchMarkMountPath ctx.Data["is_benchmark_enabled"] = setting.IsBenchmarkEnabled + ctx.Data["snn4imagenet_path"] = cloudbrain.Snn4imagenetMountPath + ctx.Data["is_snn4imagenet_enabled"] = setting.IsSnn4imagenetEnabled ctx.HTML(200, tplCloudBrainNew) } @@ -320,6 +322,23 @@ func CloudBrainBenchmark(ctx *context.Context) { ctx.Redirect(setting.BenchmarkServerHost) } +func GetRate(ctx *context.Context) { + var jobID = ctx.Params(":jobid") + job, err := models.GetCloudbrainByJobID(jobID) + if err != nil { + ctx.ServerError("GetCloudbrainByJobID failed", err) + return + } + + if job.JobType == string(models.JobTypeBenchmark) { + ctx.Redirect(setting.BenchmarkServerHost) + } else if job.JobType == string(models.JobTypeSnn4imagenet) { + ctx.Redirect(setting.Snn4imagenetServerHost) + } else { + log.Error("JobType error:", job.JobType) + } +} + func downloadCode(repo *models.Repository, codePath string) error { if err := git.Clone(repo.RepoPath(), codePath, git.CloneRepoOptions{}); err != nil { log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err) diff --git a/routers/routes/routes.go b/routers/routes/routes.go index cf5cff3ed..23e90eb77 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -911,6 +911,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/stop", reqRepoCloudBrainWriter, repo.CloudBrainStop) m.Post("/del", reqRepoCloudBrainWriter, repo.CloudBrainDel) m.Get("/benchmark", reqRepoCloudBrainWriter, repo.CloudBrainBenchmark) + m.Get("/rate", reqRepoCloudBrainWriter, repo.GetRate) }) m.Get("/create", reqRepoCloudBrainWriter, repo.CloudBrainNew) m.Post("/create", reqRepoCloudBrainWriter, bindIgnErr(auth.CreateCloudBrainForm{}), repo.CloudBrainCreate) diff --git a/templates/repo/cloudbrain/index.tmpl b/templates/repo/cloudbrain/index.tmpl index e2197e3b8..0dc0aa090 100755 --- a/templates/repo/cloudbrain/index.tmpl +++ b/templates/repo/cloudbrain/index.tmpl @@ -269,7 +269,7 @@
- + 评分
diff --git a/templates/repo/cloudbrain/new.tmpl b/templates/repo/cloudbrain/new.tmpl index b72556678..ddbe087d3 100755 --- a/templates/repo/cloudbrain/new.tmpl +++ b/templates/repo/cloudbrain/new.tmpl @@ -84,6 +84,10 @@ .inline.required.field.cloudbrain_benchmark { display: none; } + + .inline.required.field.cloudbrain_snn4imagenet { + display: none; + }
@@ -112,7 +116,7 @@
-
+
+
+ + +