예제 #1
0
        public string Run(int inputId, int targetId, List <GridConfiguration> configurations, MonoBehaviour owner)
        {
            Debug.Log("Grid.Run");

            var inputTensor  = controller.floatTensorFactory.Get(inputId);
            var targetTensor = controller.floatTensorFactory.Get(targetId);

            // write the input and target tensors to Ipfs
            var inputJob  = new Ipfs();
            var targetJob = new Ipfs();

            var inputIpfsResponse  = inputJob.Write(inputTensor.GetConfig());
            var targetIpfsResponse = targetJob.Write(targetTensor.GetConfig());

            Debug.Log("Input Hash: " + inputIpfsResponse.Hash);
            Debug.Log("Target Hash: " + targetIpfsResponse.Hash);

            var jobs = new string[configurations.Count];

            for (var i = 0; i < configurations.Count; ++i)
            {
                var config          = configurations[i];
                var model           = controller.GetModel(config.model) as Sequential;
                var serializedModel = model.GetConfig();

                var configJob     = new Ipfs();
                var ipfsJobConfig = new IpfsJobConfig(config.lr, config.criterion, config.iters);

                var response = configJob.Write(new IpfsJob(inputIpfsResponse.Hash, targetIpfsResponse.Hash, serializedModel, ipfsJobConfig));

                jobs[i] = response.Hash;
            }

            var experiment         = new IpfsExperiment(jobs);
            var experimentWriteJob = new Ipfs();
            var experimentResult   = experimentWriteJob.Write(experiment);

            BlockChain chain = Camera.main.GetComponent <BlockChain>();

            owner.StartCoroutine(chain.AddExperiment(experimentResult.Hash, jobs));
            experiments.Add(experimentResult.Hash);

            return(experimentResult.Hash);
        }