public ProcessRawCalves(BBModel bbModel, ICalvingHerdAssignment herdAssignment, ICalvingSexCodeAssignment sexCode, ICalvingTwinProcessing twinProcessing) { _bbModel = bbModel; _herdAssignment = herdAssignment; _sexCodeAssignment = sexCode; _twinProcessing = twinProcessing; }
public ImportCalving(ICSVFileReader csvFileReader, IProcessRawCalves calfProcesssor, ICalvingValidateRawCalves validator, IWriteToDatababase dbwriter, BBModel model) { _csvFileReader = csvFileReader; _calfProcesssor = calfProcesssor; _validator = validator; _dbwriter = dbwriter; _model = model; }
public void Test() { Console.WriteLine("Testing database"); _model = new BBModel(); int lastSN = _model.GetLastSN(); Console.WriteLine("Current last SN:{0}", _model.GetLastSN()); var newLastSN = _model.ReserveSNRange(3); Console.WriteLine("Resered 3 serial numbers. From {0} to {1}", newLastSN - 3, newLastSN); //_model.SetLastSN(lastSN); }
void ThreadedWork() { while (true) { if (pixelsUpdated) { Debug.Log("start"); TFShape shape = new TFShape(1, INPUT_SIZE, INPUT_SIZE, 3); var tensor = TFTensor.FromBuffer(shape, pixels, 0, pixels.Length); var runner = session.GetRunner(); runner.AddInput(graph["input"][0], tensor).Fetch(graph["output"][0]); Debug.Log("init"); output = runner.Run(); output = runner.Run(); Debug.Log("end"); var result = (float[, , , ])output[0].GetValue(false); Debug.Log("end"); int H = result.GetLength(1); int W = result.GetLength(2); int C = 20; float max_temp = 0f; List <List <float> > classes = new List <List <float> >(); List <BoundingBox> boxes = new List <BoundingBox>(); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { for (int k = 0; k < 5; k++) { List <float> current = new List <float>(); classes.Add(current); BoundingBox bb = new BoundingBox(); float arr_max = 0; float sum = 0; bb.x = (exp_c(result[0, i, j, k * 25 + 0]) + j) / (float)W; bb.y = (exp_c(result[0, i, j, k * 25 + 1]) + i) / (float)H; bb.w = Mathf.Exp(result[0, i, j, k * 25 + 2]) * anchors[2 * k + 0] / (float)W; bb.h = Mathf.Exp(result[0, i, j, k * 25 + 3]) * anchors[2 * k + 1] / (float)H; bb.c = exp_c(result[0, i, j, k * 25 + 4]); boxes.Add(bb); //Debug.Log(box_0 + "\t" + box_1 + "\t" + box_2 + "\t" + box_3 + "\t" + box_4); for (int c = 0; c < C; c++) { arr_max = Mathf.Max(arr_max, result[0, i, j, k * 25 + 5 + c]); } for (int c = 0; c < C; c++) { float x = Mathf.Exp(result[0, i, j, k * 25 + 5 + c] - arr_max); sum += x; current.Add(x); } for (int c = 0; c < C; c++) { float temp = current[c] * bb.c / sum; max_temp = Mathf.Max(temp, max_temp); if (temp > 0.05f) { current[c] = temp; } else { current[c] = 0; } //arr_max = Mathf.Max(arr_max, result[0, i, j, k * 25 + 5 + c]); } } } } var indexes = new HashSet <int>(); var final_boxes = new List <BoundingBox>(); for (int c = 0; c < C; c++) { for (int i = 0; i < H * W * 5; i++) { if (classes[i][c] < float.Epsilon) { continue; } Debug.Log("yeah"); for (int j = i + 1; j < H * W * 5; j++) { if (classes[j][c] < float.Epsilon) { continue; } if (j == i) { continue; } if (box_iou_c(boxes[i], boxes[j]) >= 0.4f) { if (classes[j][c] > classes[i][c]) { classes[i][c] = 0; break; } classes[j][c] = 0; } } if (!indexes.Contains(i)) { var bb = boxes[i]; bb.probs = classes[i]; final_boxes.Add(bb); indexes.Add(i); } } } models.Clear(); foreach (var bb in final_boxes) { BBModel model = process_box(bb, INPUT_SIZE, INPUT_SIZE, 0.2f); Debug.Log(model.bb.x + " " + model.bb.y + " " + model.bb.w + " " + model.bb.h + " " + model.prob); if (!string.IsNullOrEmpty(model.label)) { models.Add(model); } } pixelsUpdated = false; } } }
private static void Main(string[] args) { //new DatabaseTests().Test(); //new CalvingFileReaderTests().Test(); var cfr = new CalvingFileReader(); var sut = new CSVFileReader(cfr); Console.WriteLine("DigestFile processing file: {0}", TestingConstants.TestCSVFileName); var listOfRawCalves = sut.DigestFile(TestingConstants.TestCSVFileName); Console.WriteLine("DigestFile returned {0} raw calves.", listOfRawCalves.Count); foreach (var calf in listOfRawCalves) { Console.WriteLine("Tag:{0}", calf.TagNumber); } /* foreach (var rawCalf in listOfRawCalves) * { * rawCalf.HerdSN = LookupHerdSN(rawCalf.Group); * } */ var bbModel = new BBModel(); /* // Eliminate some calves * var calvingDoNotImport = new CalvingDoNotImport(); * calvingDoNotImport.DoNotImport(listOfRawCalves);*/ // Herd Assignment var calvingHerdAssignment = new CalvingHerdAssignment(bbModel); IEnumerable <Herd> herds = calvingHerdAssignment.GroupByHerd(listOfRawCalves); // Gender => Sex_Code var calvingSexCodeAssignment = new CalvingSexCodeAssignment(); calvingSexCodeAssignment.SetSexCode(herds); // Validate var validator = new CalvingValidateRawCalves(bbModel); var issues = validator.Validate(herds); if (issues.Count > 0) { Console.WriteLine("{0} FATAL ISSUES FOUND ---- CAN NOT IMPORT.", issues.Count); foreach (var issue in issues) { Console.WriteLine(issue); } Console.WriteLine(); } else { // Write the calves var bldr = new CalvingCalfBuilder(); var writer = new WriteToDatababase(bbModel, bldr); var totalImportCount = writer.WriteCalfData(herds); Console.WriteLine("\nNUMBER OF CALVES IMPORTED:{0}", totalImportCount); } Console.Write("Hit Enter to quit the test harness"); Console.Read(); }
public CalvingValidateRawCalves(BBModel bbModel) { _bbModel = bbModel; }
public CalvingHerdAssignment(BBModel model) { _model = model; }
public WriteToDatababase(BBModel model, ICalvingCalfBuilder calfBuilder) { _model = model; _calfBuilder = calfBuilder; }
public CalvingTwinProcessing(BBModel bbModel) { _bbModel = bbModel; }