public ActionResult AddTask(LearningTask task, int flowId) { if (ModelState.IsValid) { var flow = LearningFlowService.Get(flowId); if (flow != null) { task.Name = Server.HtmlEncode(task.Name); flow.Tasks.Add(task); LearningFlowService.Update(flow); return this.Json(Is.Success.Message(task.ID.ToString())); } Logger.Warn("User tried to add task to non existing flow"); return this.Json(Is.Fail.Message("Flow doesn't exist")); } Logger.Warn("Add Task - Validation Fail"); return this.Json(Is.Fail.Message("Valdiation Failed")); }
private void EditTask(int index) { childToEditIndex = index; LearningTask toEdit = thisTask.ChildTasks.ElementAt(index); switch (toEdit.TaskType.IdName) { case "LISTEN_AUDIO": PerformSegue("EditListenAudioChildTask", this); break; case "INFO": PerformSegue("EditInfoChildTask", this); break; case "MULT_CHOICE": PerformSegue("EditMultiChoiceChildTask", this); break; case "MAP_MARK": PerformSegue("EditMapMarkChildTask", this); break; case "LOC_HUNT": PerformSegue("EditLocationHuntChildTask", this); break; case "DRAW_PHOTO": case "MATCH_PHOTO": PerformSegue("EditChoosePhotoChildTask", this); break; default: PerformSegue("EditChildTask", this); break; } }
/// <summary> /// Created By : Maulik Joshi /// Created On : 14th November, 2016 /// Purpose : Update task. /// </summary> /// <param name="task"></param> /// <returns></returns> public async Task UpdetTask(LearningTask task) { if (task == null) { return; } try { if (task.Id == Guid.Empty) { await this.client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), task); } else { await this.client.ReplaceDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collectionName, task.Id.ToString()), task); } } catch (DocumentClientException) { throw; } }
private static TaskFileInfo GetInfoForTask(LearningTask task) { string tt = task.TaskType?.IdName; if (tt == "MATCH_PHOTO" || tt == "LISTEN_AUDIO" || (tt == "DRAW_PHOTO" && !task.JsonData.StartsWith("TASK::", StringComparison.OrdinalIgnoreCase))) { return(new TaskFileInfo { extension = ServerUtils.GetFileExtension(task.TaskType.IdName), fileUrl = task.JsonData }); } else if (tt == "INFO") { AdditionalInfoData infoData = JsonConvert.DeserializeObject <AdditionalInfoData>(task.JsonData); if (!string.IsNullOrWhiteSpace(infoData.ImageUrl)) { return(new TaskFileInfo { extension = ServerUtils.GetFileExtension(task.TaskType.IdName), fileUrl = infoData.ImageUrl }); } } return(null); }
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { if (resultCode != Result.Ok) { return; } if (requestCode == AddTaskIntent) { LearningTask newTask = JsonConvert.DeserializeObject <LearningTask>(data.GetStringExtra("JSON")); adapter.data.Add(newTask); adapter.NotifyDataSetChanged(); } else if (requestCode == EditTaskIntent) { LearningTask returned = JsonConvert.DeserializeObject <LearningTask>(data.GetStringExtra("JSON")); int foundIndex = adapter.data.FindIndex(t => t.Id == returned.Id); if (foundIndex != -1) { adapter.data[foundIndex] = returned; adapter.NotifyDataSetChanged(); } } }
public override void ViewDidLoad() { base.ViewDidLoad(); InitKeyboardHandling(); DismissKeyboardOnBackgroundTap(); if (thisActivity == null) { NavigationController.PopViewController(true); return; } if (thisActivity.LearningTasks == null) { thisActivity.LearningTasks = new List <LearningTask>(); } // check if we're editing an existing task if (thisActivity.LearningTasks.ToList().Count > parentTaskIndex) { if (childTaskIndex != null) { var parent = thisActivity.LearningTasks.ToList()[parentTaskIndex]; if (parent.ChildTasks != null & parent.ChildTasks.Count() > childTaskIndex) { thisTask = parent.ChildTasks.ToList()[(int)childTaskIndex]; thisTaskType = thisTask.TaskType; } } else { thisTask = thisActivity.LearningTasks.ToList()[parentTaskIndex]; thisTaskType = thisTask.TaskType; } UIBarButtonItem customButton = new UIBarButtonItem( UIImage.FromFile("ic_delete"), UIBarButtonItemStyle.Plain, (s, e) => { ConfirmDelete(); } ); NavigationItem.RightBarButtonItem = customButton; } if (thisTaskType == null) { NavigationController.PopViewController(true); } NavigationItem.Title = thisTaskType.DisplayName; ImageService.Instance.LoadUrl(thisTaskType.IconUrl).Into(TaskTypeIcon); FinishButton.TouchUpInside += FinishButton_TouchUpInside; // style the text view to look like a text field - why the hell are they different? TaskDescription.Layer.BorderColor = UIColor.Gray.ColorWithAlpha(0.5f).CGColor; TaskDescription.Layer.BorderWidth = 2; TaskDescription.Layer.CornerRadius = 5; TaskDescription.ClipsToBounds = true; if (thisTask != null) { TaskDescription.Text = thisTask.Description; FinishButton.SetTitle("Save Changes", UIControlState.Normal); } else { // Add placeholder text TaskDescription.Delegate = new TextViewPlaceholderDelegate(TaskDescription, placeholderText); } }
public LearningTaskDisplay(LearningTask selectedTask) { InitializeComponent(); _task = selectedTask; LoadTaskData(); }
private void AddTaskBtn_Click(object sender, EventArgs e) { int errMess = -1; int min = int.Parse(minNumText.Text); int max = int.Parse(maxNumText.Text); if (string.IsNullOrWhiteSpace(instructions.Text)) { errMess = Resource.String.createNewActivityTaskInstruct; } else if (min < 1) { errMess = Resource.String.createNewMapMarkerErrMinLessThanOne; } else if (max < min && max != 0) { errMess = Resource.String.createNewMapMarkerErrMaxLessThanMin; } if (errMess != -1) { new global::Android.Support.V7.App.AlertDialog.Builder(this) .SetTitle(Resource.String.ErrorTitle) .SetMessage(errMess) .SetPositiveButton(Resource.String.dialog_ok, (a, b) => { }) .Show(); return; } MapMarkerTaskData taskData = new MapMarkerTaskData { MaxNumMarkers = max, MinNumMarkers = min, UserLocationOnly = userLocOnlyCheckbox.Checked }; if (newTask == null) { newTask = new LearningTask() { TaskType = taskType }; } newTask.Description = instructions.Text; newTask.JsonData = JsonConvert.SerializeObject(taskData); string json = JsonConvert.SerializeObject(newTask, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Serialize, MaxDepth = 5 }); Intent myIntent = (editing) ? new Intent(this, typeof(CreateActivityOverviewActivity)) : new Intent(this, typeof(CreateChooseTaskTypeActivity)); myIntent.PutExtra("JSON", json); SetResult(global::Android.App.Result.Ok, myIntent); Finish(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.LocationHunActivity); string thisJsonData = Intent.GetStringExtra("JSON") ?? ""; learningTask = JsonConvert.DeserializeObject <LearningTask>(thisJsonData, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto }); if (learningTask == null) { learningTask = new LearningTask() { Description = Intent.GetStringExtra("Description"), }; target = JsonConvert.DeserializeObject <LocationHuntLocation>(Intent.GetStringExtra("Target")); } else { target = JsonConvert.DeserializeObject <LocationHuntLocation>(learningTask.JsonData); } SupportActionBar.Title = learningTask.Description; TextView taskDesc = FindViewById <TextView>(Resource.Id.taskDesc); taskDesc.Text = learningTask.Description; distanceText = FindViewById <TextView>(Resource.Id.distanceText); distanceText.Text = "Please wait"; Color.Rgb( Color.GetRedComponent(distanceText.CurrentTextColor), Color.GetGreenComponent(distanceText.CurrentTextColor), Color.GetBlueComponent(distanceText.CurrentTextColor)); accuracyText = FindViewById <TextView>(Resource.Id.accuracyText); accuracyText.Text = "Connecting"; image = FindViewById <ImageView>(Resource.Id.taskImage); image.Alpha = LowAlpha; Button openMapButton = FindViewById <Button>(Resource.Id.openMapButton); openMapButton.Click += OpenMapButton_Click; openMapButton.Visibility = (target.MapAvailable == null || target.MapAvailable == true) ? ViewStates.Visible : ViewStates.Gone; if (!AndroidUtils.IsGooglePlayServicesInstalled(this) || googleApiClient != null) { return; } googleApiClient = new GoogleApiClient.Builder(this) .AddConnectionCallbacks(this) .AddOnConnectionFailedListener(this) .AddApi(LocationServices.API) .Build(); locRequest = new LocationRequest(); }
private void AddTaskBtn_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(instructions.Text)) { new global::Android.Support.V7.App.AlertDialog.Builder(this) .SetTitle(Resource.String.ErrorTitle) .SetMessage(Resource.String.createNewActivityTaskInstruct) .SetPositiveButton(Resource.String.dialog_ok, (a, b) => { }) .Show(); return; } if (selectedImage == null && useParent == false && (newTask == null || string.IsNullOrWhiteSpace(newTask.JsonData))) { new global::Android.Support.V7.App.AlertDialog.Builder(this) .SetTitle(Resource.String.ErrorTitle) .SetMessage(Resource.String.createNewDrawPhotoNothingSelected) .SetPositiveButton(Resource.String.dialog_ok, (a, b) => { }) .Show(); return; } if (newTask == null) { newTask = new LearningTask { TaskType = taskType }; } newTask.Description = instructions.Text; if (selectedImage != null) { if (!editing || selectedImage.Path != editCachePath) { newTask.JsonData = selectedImage.Path; } } else if (useParent) { newTask.JsonData = "TASK::" + parentTask.Id; if (outputFileUri != null && File.Exists(outputFileUri.Path)) { File.Delete(outputFileUri.Path); } } string json = JsonConvert.SerializeObject(newTask, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Serialize, MaxDepth = 5 }); Intent myIntent; if (isChild && editing) { myIntent = new Intent(this, typeof(CreateManageChildTasksActivity)); } else { myIntent = (editing) ? new Intent(this, typeof(CreateActivityOverviewActivity)) : new Intent(this, typeof(CreateChooseTaskTypeActivity)); } myIntent.PutExtra("JSON", json); SetResult(global::Android.App.Result.Ok, myIntent); Finish(); }
private void ManageChildenClicked(LearningTask task) { manageChildrenClicked?.Invoke(Rows.IndexOf(task)); }
private void EditClicked(LearningTask task) { editClicked?.Invoke(Rows.IndexOf(task)); }
internal Optional <ProgramSet> LearnDupLet(SynthesisEngine engine, LetRule rule, LearningTask <DisjunctiveExamplesSpec> task, CancellationToken cancel) { var examples = task.Spec; List <string[]> pathsArr = new List <string[]>(); foreach (KeyValuePair <State, IEnumerable <object> > example in examples.DisjunctiveExamples) { State inputState = example.Key; var input = example.Key[Grammar.InputSymbol] as MergeConflict; List <string> idx = new List <string>(); foreach (IReadOnlyList <Node> output in example.Value) { foreach (Node n in Semantics.Concat(input.Upstream, input.Downstream)) { bool flag = false; n.Attributes.TryGetValue(Path, out string inPath); foreach (Node node in output) { node.Attributes.TryGetValue(Path, out string outputPath); if (inPath == outputPath) { flag = true; } } if (!flag) { idx.Add(inPath); } } } pathsArr.Add(idx.ToArray()); } pathsArr.Add(new string[1] { string.Empty }); List <ProgramSet> programSetList = new List <ProgramSet>(); foreach (string[] path in pathsArr) { NonterminalRule findMatchRule = Grammar.Rule(nameof(Semantics.FindMatch)) as NonterminalRule; ProgramSet letValueSet = ProgramSet.List( Grammar.Symbol("find"), new NonterminalNode( findMatchRule, new VariableNode(Grammar.InputSymbol), new LiteralNode(Grammar.Symbol("paths"), path))); var bodySpec = new Dictionary <State, IEnumerable <object> >(); foreach (KeyValuePair <State, IEnumerable <object> > kvp in task.Spec.DisjunctiveExamples) { State input = kvp.Key; MergeConflict x = (MergeConflict)input[Grammar.InputSymbol]; List <IReadOnlyList <Node> > dupValue = Semantics.FindMatch(x, path); State newState = input.Bind(rule.Variable, dupValue); bodySpec[newState] = kvp.Value; } LearningTask bodyTask = task.Clone(rule.LetBody, new DisjunctiveExamplesSpec(bodySpec)); ProgramSet bodyProgramSet = engine.Learn(bodyTask, cancel); var dupLetProgramSet = ProgramSet.Join(rule, letValueSet, bodyProgramSet); programSetList.Add(dupLetProgramSet); } ProgramSet ps = new UnionProgramSet(rule.Head, programSetList.ToArray()); return(ps.Some()); }
private void Learn(int taskIndex, LearningTask task, CancellationToken cancellationToken) { using (StreamWriter logFile = File.CreateText(task.LogFileName)) { logFile.AutoFlush = true; try { // report starting time DateTime dateStarted = DateTime.Now; this.WriteLine(logFile, string.Format(CultureInfo.InvariantCulture, "Started: {0}", dateStarted.ToString("G", CultureInfo.InvariantCulture))); ClassificationNetwork net = File.Exists(task.Architecture) ? ClassificationNetwork.FromFile(task.Architecture) : ClassificationNetwork.FromArchitecture(task.Architecture, task.Classes, task.Classes, task.BlankClass); // learning Learn(); net.SaveToFile(task.OutputFileName, NetworkFileFormat.JSON); // report finish time and processing interval DateTime dateFinished = DateTime.Now; this.WriteLine(logFile, string.Empty); this.WriteLine(logFile, string.Format(CultureInfo.InvariantCulture, "Finished: {0:G}", dateFinished)); this.WriteLine(logFile, string.Format(CultureInfo.InvariantCulture, "Total time: {0:g}", TimeSpan.FromSeconds((dateFinished - dateStarted).TotalSeconds))); void Learn() { this.WriteLine(logFile, "Learning..."); ImageDistortion filter = new ImageDistortion(); Stopwatch timer = new Stopwatch(); this.WriteLine(logFile, " Epochs: {0}", task.Epochs); this.WriteTrainerParameters(logFile, task.Trainer, task.Algorithm, task.Loss); this.WriteLine(logFile, "Image distortion:"); this.WriteLine(logFile, " Shift: {0}", task.Shift); this.WriteLine(logFile, " Rotate: {0}", task.Rotate); this.WriteLine(logFile, " Scale: {0}", task.Scale); this.WriteLine(logFile, " Crop: {0}", task.Crop); Shape shape = net.InputShape; using (TestImageProvider <string> dataProvider = task.CreateDataProvider(net)) { using (TestImageProvider <string> testDataProvider = task.CreateTestDataProvider(net)) { ////int n = 0; for (int epoch = 0; epoch < task.Epochs; epoch++) { // run learning timer.Restart(); TrainingResult result = task.Trainer.RunEpoch( epoch, net, GenerateLearnSamples(dataProvider, epoch), task.Algorithm, task.Loss, cancellationToken); timer.Stop(); lock (this.logLocker) { string s = string.Format( CultureInfo.InvariantCulture, "Net: {0}, Epoch: {1}, Time: {2} ms, {3}", taskIndex, epoch, timer.ElapsedMilliseconds, result); this.Write(logFile, s); ////this.WriteDebugInformation(logFile); this.WriteLine(logFile, string.Empty); } // run testing string epochOutputFileName = string.Format(CultureInfo.InvariantCulture, task.EpochFileNameTemplate, epoch); // save network net.SaveToFile(epochOutputFileName, NetworkFileFormat.JSON); // run testing List <ClassificationResult <string> > results = new List <ClassificationResult <string> >(); if (task.Loss is CTCLoss) { Context model = Context.FromRegex(@"\d", CultureInfo.InvariantCulture); foreach ((TestImage image, string[] labels) in GenerateTestSamples(testDataProvider)) { if (image.Image.IsAllWhite()) { results.Add(new ClassificationResult <string>( image.SourceId, "0", string.Concat(labels), 1.0f, true)); } else { Tensor x = ImageExtensions.FromImage(image.Image, null, Shape.BWHC, shape.GetAxis(Axis.X), shape.GetAxis(Axis.Y)); (string text, float prob) = net.ExecuteSequence(x, model).Answers.FirstOrDefault(); results.Add(new ClassificationResult <string>( image.SourceId, text, string.Concat(labels), prob, prob >= 0.38f)); } } } else { foreach ((TestImage image, string[] labels) in GenerateTestSamples(testDataProvider)) { if (image.Image.IsAllWhite()) { results.Add(new ClassificationResult <string>( image.SourceId, "0", string.Concat(labels), 1.0f, true)); } else { Tensor x = ImageExtensions.FromImage(image.Image, null, Shape.BWHC, shape.GetAxis(Axis.X), shape.GetAxis(Axis.Y)); foreach (IList <(string answer, float probability)> answer in net.Execute(x).Answers) { string text = answer.FirstOrDefault().answer; float prob = answer.FirstOrDefault().probability; results.Add(new ClassificationResult <string>( image.SourceId, text, string.Concat(labels), prob, prob >= 0.38f)); } } } } // write report ClassificationReport <string> testReport = new ClassificationReport <string>(results); this.Write(logFile, ClassificationReportWriter <string> .WriteReport(testReport, ClassificationReportMode.Summary)); using (StreamWriter outputFile = File.CreateText(Path.ChangeExtension(epochOutputFileName, ".res"))) { ClassificationReportWriter <string> .WriteReport(outputFile, testReport, ClassificationReportMode.All); } } } IEnumerable <(Tensor x, string[] labels)> GenerateLearnSamples(TestImageProvider <string> provider, int epoch) { return(GenerateSamples(provider) .Where(x => !x.image.Image.IsAllWhite()) .SelectMany(x => { if (epoch == 0) { ////x.Image.Save("e:\\temp\\" + x.Id + "_" + n.ToString(CultureInfo.InvariantCulture) + "_.bmp"); } return filter .Distort( x.image.Image, shape.GetAxis(Axis.X), shape.GetAxis(Axis.Y), task.Shift, task.Rotate && x.image.FontStyle != FontStyle.Italic, task.Scale, task.Crop) .Select(bitmap => { if (epoch == 0) { ////Interlocked.Increment(ref n); ////bitmap.Save(@"d:\dnn\temp\" + n.ToString(CultureInfo.InvariantCulture) + ".bmp"); ////bitmap.Save(@"d:\dnn\temp\" + (n).ToString(CultureInfo.InvariantCulture) + "_" + x.SourceId.Id + ".bmp"); } return (ImageExtensions.FromImage(bitmap, null, Shape.BWHC, shape.GetAxis(Axis.X), shape.GetAxis(Axis.Y)), x.labels); }); })); } IEnumerable <(TestImage image, string[] labels)> GenerateTestSamples(TestImageProvider <string> provider) { return(GenerateSamples(provider) .AsParallel() .AsOrdered() .WithCancellation(cancellationToken) .WithMergeOptions(ParallelMergeOptions.AutoBuffered)); } IEnumerable <(TestImage image, string[] labels)> GenerateSamples(TestImageProvider <string> provider) { return(provider .Generate(net.AllowedClasses) .Select(x => { string[] labels = x.Labels; if (!(task.Loss is CTCLoss)) { int b = net.OutputShapes.First().GetAxis(Axis.B); if (labels.Length == 1 && b > 1) { labels = Enumerable.Repeat(labels[0], b).ToArray(); } } return (x, labels); })); } } } } finally { logFile.Flush(); } } }