Ejemplo n.º 1
0
    def predict(self, node_id, filelist):
        '''
        predict inti run
        :param node_id: 
        :param filelist: 
        :return: 
        '''
        logging.info("run NeuralNetNodeCnn Predict")
        # init data setup
        self.node_id = node_id
        self._init_value()
        # net, data config setup
        data_node_name = self._get_backward_node_with_type(node_id, 'data')
        dataconf = WorkFlowNetConfCNN().get_view_obj(data_node_name[0])

        netconf = WorkFlowNetConfCNN().get_view_obj(self.node_id)
        self.netconf = netconf

        self._set_netconf_parm()
        self._set_dataconf_parm(dataconf)

        # get unique key
        self.load_batch = self.get_active_batch(self.node_id)
        unique_key = '_'.join([node_id, self.load_batch])



        # prepare net conf
        tf.reset_default_graph()

        self.get_model_cnn("P")

        ## create tensorflow graph
        try:
            if (NeuralNetModel.dict.get(unique_key)):
                self = NeuralNetModel.dict.get(unique_key)
                graph = NeuralNetModel.graph.get(unique_key)

                with tf.Session(graph=graph) as sess:
                    self._run_predict(sess, filelist)
            else:
                with tf.Session() as sess:
                    self._run_predict(sess, filelist)
        except Exception as e:
            self.get_model_cnn("P")
            with tf.Session() as sess:
                self._run_predict(sess, filelist)

        NeuralNetModel.dict[unique_key] = self
        NeuralNetModel.graph[unique_key] = tf.get_default_graph()
        graph = tf.get_default_graph()



        return self.pred_return_data
Ejemplo n.º 2
0
    def _set_netconf_parm(self):
        netconf = WorkFlowNetConfCNN().get_view_obj(self.node_id)
        try:
            netconf = WorkFlowNetConfCNN().set_num_classes_predcnt(
                self.nn_id, self.wf_ver, self.node, self.node_id, netconf)
        except:
            None
        self.netconf = netconf

        self.train_cnt = self.netconf["param"]["traincnt"]
        self.epoch = self.netconf["param"]["epoch"]
        self.batch_size = self.netconf["param"]["batch_size"]
        self.model_path = self.netconf["modelpath"]
        self.modelname = self.netconf["modelname"]
Ejemplo n.º 3
0
 def get(self, request, nnid, ver, node):
     """
     - desc : get data
     """
     try:
         nodeid = ''.join([nnid, '_', ver, '_', node])
         return_data = WorkFlowNetConfCNN().get_view_obj(nodeid)
         return Response(json.dumps(return_data))
     except Exception as e:
         return_data = {"status": "404", "result": str(e)}
         return Response(json.dumps(return_data))
 def put(self, request, nnid, ver, node):
     """
     - desc ; update data
     """
     try:
         input_data = json.loads(str(request.body, 'utf-8'))
         node_id = nnid+'_'+ver+'_'+node
         return_data = WorkFlowNetConfCNN().set_view_obj_path(nnid, ver, node, node_id, input_data)
         return Response(json.dumps(return_data))
     except Exception as e:
         return_data = {"status": "404", "result": str(e)}
         return Response(json.dumps(return_data))
Ejemplo n.º 5
0
    def predict(self, node_id, filelist):
        """
        """
        logging.info("run NeuralNetNodeCnn Predict")
        self.node_id = node_id
        self._init_value()
        # net, data config setup
        data_node_name = self._get_backward_node_with_type(node_id, 'data')
        dataconf = WorkFlowNetConfCNN().get_view_obj(data_node_name[0])
        self._set_netconf_parm()
        self._set_dataconf_parm(dataconf)

        # data shape change MultiValuDict -> nd array
        filename_arr, filedata_arr = self.change_predict_fileList(
            filelist, dataconf)

        # get unique key
        self.load_batch = self.get_active_batch(self.node_id)
        unique_key = '_'.join([node_id, self.load_batch])

        logging.info("getModelPath:" + self.model_path + "/" +
                     self.load_batch + self.file_end)

        ## create tensorflow graph
        if (NeuralNetModel.dict.get(unique_key)):
            self = NeuralNetModel.dict.get(unique_key)
            graph = NeuralNetModel.graph.get(unique_key)
        else:
            self.get_model_resnet()

            NeuralNetModel.dict[unique_key] = self
            NeuralNetModel.graph[unique_key] = tf.get_default_graph()
            graph = tf.get_default_graph()
        pred_return_data = {}
        for i in range(len(filename_arr)):
            file_name = filename_arr[i]
            file_data = filedata_arr[i]

            logits = self.model.predict(file_data)

            labels = self.netconf["labels"]
            pred_cnt = self.netconf["param"]["predictcnt"]
            retrun_data = self.set_predict_return_cnn_img(
                labels, logits, pred_cnt)
            pred_return_data[file_name] = retrun_data
            logging.info("Return Data.......................................")
            logging.info(pred_return_data)

        return pred_return_data
Ejemplo n.º 6
0
    def run(self, conf_data):
        '''
        Train run init
        :param conf_data: 
        :return: 
        '''
        try:
            logging.info("run NeuralNetNodeResnet Train")
            # init data setup
            self._init_train_parm(conf_data)
            self._init_value()

            # get data & dataconf
            test_data, dataconf = self.get_input_data(self.feed_node,
                                                      self.cls_pool,
                                                      self.eval_feed_name)
            input_data, dataconf = self.get_input_data(self.feed_node,
                                                       self.cls_pool,
                                                       self.train_feed_name)

            # set netconf, dataconf
            netconf = WorkFlowNetConfCNN().get_view_obj(self.node_id)
            self.netconf = netconf
            self._set_netconf_labels(input_data)
            self._set_netconf_parm()
            self._set_dataconf_parm(dataconf)

            # set batch
            self.load_batch = self.get_eval_batch(self.node_id)
            if self.epoch != 0 and self.train_cnt != 0:
                self.train_batch, self.batch = self.make_batch(self.node_id)
            else:
                self.batch = self.load_batch

            self.get_model_resnet()

            self.train_run_resnet(input_data, test_data)

            self.train_return_data["TrainResult"] = self.train_return_arr

            if self.epoch == 0 or self.train_cnt == 0:
                self.eval(self.node_id, self.conf_data, None, None)

            return self.train_return_data
        except Exception as e:
            logging.info("===Error on running residualnet : {0}".format(e))
Ejemplo n.º 7
0
    def run(self, conf_data):
        '''
        init run 
        :param conf_data: 
        :return: 
        '''
        try :
            logging.info("run NeuralNetNodeCnn Train")
            # init data setup
            self._init_train_parm(conf_data)
            self._init_value()

            # get data & dataconf
            test_data, dataconf = self.get_input_data(self.feed_node, self.cls_pool, self.eval_feed_name)
            input_data, dataconf = self.get_input_data(self.feed_node, self.cls_pool, self.train_feed_name)

            # set netconf, dataconf
            netconf = WorkFlowNetConfCNN().get_view_obj(self.node_id)
            self.netconf = netconf
            self._set_netconf_labels(input_data)
            self._set_netconf_parm()
            self._set_dataconf_parm(dataconf)

            # set batch
            self.load_batch = self.get_eval_batch(self.node_id)
            if self.epoch != 0 and self.train_cnt != 0:
                self.train_batch, self.batch = self.make_batch(self.node_id)
            else:
                self.batch = self.load_batch

            self.get_model_cnn("T")

            # train
            with tf.Session() as sess:
                sess = self.get_saver_model(sess)
                sess.run(tf.global_variables_initializer())
                self.train_run_cnn(sess, input_data, test_data)

            self.train_return_data["TrainResult"] = self.train_return_arr

            if self.epoch == 0 or self.train_cnt == 0:
                self.eval(self.node_id, self.conf_data, None, None)

            return self.train_return_data
        except Exception as e :
            logging.info("[Basic CNN Train Process] : {0}".format(e))
Ejemplo n.º 8
0
    def predict(self, node_id, filelist):
        """
        """
        println("run NeuralNetNodeCnn Predict")
        # init data setup
        self.node_id = node_id
        self._init_value()
        # net, data config setup
        data_node_name = self._get_backward_node_with_type(node_id, 'data')
        dataconf = WorkFlowNetConfCNN().get_view_obj(data_node_name[0])
        self._set_netconf_parm()
        self._set_dataconf_parm(dataconf)
        self.net_type = self.netconf["config"]["net_type"]

        # get unique key
        unique_key = '_'.join([node_id, self.get_eval_batch(node_id)])

        # prepare net conf
        tf.reset_default_graph()

        ## create tensorflow graph
        if (NeuralNetModel.dict.get(unique_key)):
            self = NeuralNetModel.dict.get(unique_key)
            graph = NeuralNetModel.graph.get(unique_key)

            with tf.Session(graph=graph) as sess:
                self._run_predict(sess, filelist)
        else:
            self.get_model_cnn("P")
            NeuralNetModel.dict[unique_key] = self
            NeuralNetModel.graph[unique_key] = tf.get_default_graph()
            graph = tf.get_default_graph()

            with tf.Session() as sess:
                self._run_predict(sess, filelist)

        return self.pred_return_data
    def predict(self, node_id, filelist):
        """
        """
        println("run NeuralNetNodeCnn Predict")
        # init data setup
        self._init_predict_parm(node_id)
        self._init_value()
        # net, data config setup
        data_node_name = self._get_backward_node_with_type(node_id, 'data')
        dataconf = WorkFlowNetConfCNN().get_view_obj(data_node_name[0])
        self._set_netconf_parm()
        self._set_dataconf_parm(dataconf)
        self.net_type = self.netconf["config"]["net_type"]

        # data shape change MultiValuDict -> nd array
        filename_arr, filedata_arr = self.change_predict_fileList(
            filelist, dataconf)

        # get unique key
        unique_key = '_'.join([node_id, self.get_eval_batch(node_id)])

        # prepare net conf
        tf.reset_default_graph()

        ## create tensorflow graph
        if (NeuralNetModel.dict.get(unique_key)):
            self = NeuralNetModel.dict.get(unique_key)
            graph = NeuralNetModel.graph.get(unique_key)
        else:
            if self.net_type == "cnn":
                self.get_model_cnn("P")
            elif self.net_type == "resnet":
                self.get_model_resnet()

            NeuralNetModel.dict[unique_key] = self
            NeuralNetModel.graph[unique_key] = tf.get_default_graph()
            graph = tf.get_default_graph()

        # predict
        with tf.Session(graph=graph) as sess:
            sess.run(tf.global_variables_initializer())

            for i in range(len(filename_arr)):
                file_name = filename_arr[i]
                file_data = filedata_arr[i]

                if self.net_type == "cnn":
                    sess, saver = self.get_saver_model(sess)
                    logits = sess.run([self.model],
                                      feed_dict={self.X: file_data})
                    logits = logits[0]
                elif self.net_type == "resnet":
                    logits = self.model.predict(file_data)

                labels = self.netconf["labels"]
                pred_cnt = self.netconf["param"]["predictcnt"]
                retrun_data = self.set_predict_return_cnn_img(
                    labels, logits, pred_cnt)
                self.pred_return_data[file_name] = retrun_data
                println("Return Data.......................................")
                println(self.pred_return_data)

        return self.pred_return_data