public static void CopyFiles(Hyperparameters h, string source, string destination) { if (destination[destination.Length - 1] != '\\') { destination += destination + '\\'; } Directory.CreateDirectory(destination); if (source.Replace("\\\\", "\\") != destination.Replace("\\\\", "\\")) { foreach (string file in Directory.GetFiles(source)) { if (Path.GetFileName(file) != "h.json") { File.Copy(file, destination + Path.GetFileName(file), true); } } } //указание пути сохранения в параметрах h.setValueByName("save_folder", destination); string jsonFilePath = destination + "h.json"; h.setValueByName("json_file_path", jsonFilePath); string predictionsFilePath = destination + "predictions.txt"; h.setValueByName("predictions_file_path", predictionsFilePath); File.WriteAllText(jsonFilePath, h.toJSON(0), System.Text.Encoding.Default); }
public Hyperparameters Copy(Hyperparameters individ, string source, string destination) { Hyperparameters H = individ.Clone(); var algorithmBranches = H.getNodesByparentID(H.getNodeByName("committee")[0].ID); List <Hyperparameters> hs = new List <Hyperparameters>(); for (int j = 0; j < algorithmBranches.Count; j++) { var h = new Hyperparameters(H.toJSON(algorithmBranches[j].ID), form1); var new_save_folder = destination + "\\" + h.getValueByName("model_name") + "\\"; //новые пути прописываются в h.json автоматически, если передать объект Hyperparameters по ссылке, а не по значению Algorithm.CopyFiles(h, h.getValueByName("save_folder"), new_save_folder); hs.Add(h); } //удаление старых записей for (int i = 0; i < algorithmBranches.Count; i++) { H.deleteBranch(algorithmBranches[i].ID); } //приращение новых записей к узлу "committee" for (int i = 0; i < algorithmBranches.Count; i++) { H.addBranch(hs[i], hs[i].nodes[0].name(), H.getNodeByName("committee")[0].ID); } H.setValueByName("report_path", destination); H = H.Clone(); File.WriteAllText(destination + "\\h.json", H.toJSON(0), System.Text.Encoding.Default); return(H); }
public static void MoveFiles(Hyperparameters h, string source, string destination) { if (destination[destination.Length - 1] != '\\') { destination += '\\'; } Directory.CreateDirectory(destination); if (source != destination) { foreach (string file in Directory.GetFiles(destination)) { File.Delete(file); } foreach (string file in Directory.GetFiles(source)) { repeat1: try { if (Path.GetFileName(file) != "h.json") { File.Copy(file, destination + Path.GetFileName(file)); } else { File.Delete(file); } } catch { throw; goto repeat1; } } } else { } //указание пути сохранения в параметрах h.setValueByName("save_folder", destination); string jsonFilePath = destination + "h.json"; h.setValueByName("json_file_path", jsonFilePath); string predictionsFilePath = destination + "predictions.txt"; h.setValueByName("predictions_file_path", predictionsFilePath); File.WriteAllText(jsonFilePath, h.toJSON(0), System.Text.Encoding.Default); }
private void ModeSelectorButtonClick(object sender, EventArgs e) { string mode = ""; foreach (var control in modeSelector.groupBox1.Controls) { if (control.GetType() == modeSelector.radioButton1.GetType()) { RadioButton rb = (RadioButton)control; if (rb.Checked) { mode = rb.Text; } } } h.setValueByName("mode", mode); var configLines = File.ReadAllLines("CONFIG.txt").ToList(); for (int i = 0; i < configLines.Count; i++) { //параметры конфигурации начинаются со строки содержащей имя компа if (configLines[i].Contains(Environment.MachineName)) { for (int j = i + 1; j < configLines.Count; j++) { if (configLines[j].Contains("mode")) { configLines[j] = "mode:" + mode; break; } //параметры конфигурации заканчиваются, когда встречается пустая строка if (configLines[j] != "") { } else { configLines.Insert(j, "mode:" + mode); break; } } break; } } File.WriteAllLines("CONFIG.txt", configLines.ToArray()); Application.Exit(); }
public void Process() { NetworkStream stream = null; /* try * { */ stream = client.GetStream(); BinaryReader reader = new BinaryReader(stream); BinaryWriter writer = new BinaryWriter(stream); while (true) { if (task != null) { if (task.status != "done") { if (task.type == "train") { //log(hostName + ": " + task.h.getValueByName("code")+" .1"); status = "busy"; //объявление агенту типа задачи sendCommand(writer, "train"); task.h.Save(); sendFile(writer, task.h.getValueByName("json_file_path")); System.Threading.Thread.Sleep(10); sendFile(writer, task.h.getValueByName("train_script_path")); System.Threading.Thread.Sleep(10); sendFile(writer, task.h.getValueByName("input_file")); System.Threading.Thread.Sleep(10); var trainingReport = recieveCommand(reader); // log(trainingReport); if (!trainingReport.Contains("Произошла ошибка")) { recieveFile(reader, task.h.getValueByName("json_file_path")); System.Threading.Thread.Sleep(10); recieveFile(reader, task.h.getValueByName("predictions_file_path")); System.Threading.Thread.Sleep(10); recieveFile(reader, task.h.getValueByName("save_folder") + "weights.h5"); System.Threading.Thread.Sleep(10); // log(hostName + ": " + task.h.getValueByName("code") + " .2"); Hyperparameters hTemp = new Hyperparameters(File.ReadAllText(task.h.getValueByName("json_file_path"), Encoding.Default), form1); hTemp.setValueByName("json_file_path", task.h.getValueByName("json_file_path")); hTemp.setValueByName("predictions_file_path", task.h.getValueByName("predictions_file_path")); hTemp.setValueByName("save_folder", task.h.getValueByName("save_folder")); hTemp.setValueByName("train_script_path", task.h.getValueByName("train_script_path")); hTemp.setValueByName("get_prediction_script_path", task.h.getValueByName("get_prediction_script_path")); hTemp.setValueByName("input_file", task.h.getValueByName("input_file")); task.h = hTemp.Clone(); task.h.Save(); log(hostName + ": " + task.h.getValueByName("code") + " trained; accuracy = " + task.h.getValueByName("stdDev")); task.status = "done"; } else { task.status = "error"; } status = "free"; } } } System.Threading.Thread.Sleep(1000); } /* } * catch (Exception ex) * { * log(ex.Message); * } * finally * { * if (stream != null) * stream.Close(); * if (client != null) * client.Close(); * } */ }