Beispiel #1
0
def predict_ids(model_name, vg, vd):
    workspace.ResetWorkspace()

    # preproc the input
    vg = vg.astype(np.float32)
    vd = vd.astype(np.float32)
    #if len(self.preproc_param) == 0:
    preproc_param = pickle.load(open(model_name + '_preproc_param.p', "rb"))
    dummy_ids = np.zeros(len(vg))
    preproc_data_arrays = preproc.dc_iv_preproc(
        vg,
        vd,
        dummy_ids,
        preproc_param['scale'],
        preproc_param['vg_shift'],
    )
    # print(preproc_data_arrays[0].shape)
    _preproc_data_arrays = [
        np.expand_dims(x, axis=1) if len(x.shape) < 2 else x
        for x in preproc_data_arrays
    ]

    workspace.FeedBlob('DBInput_train/sig_input', _preproc_data_arrays[0])
    workspace.FeedBlob('DBInput_train/tanh_input', _preproc_data_arrays[1])
    pred_net = exporter.load_net(model_name + '_init', model_name + '_predict')

    workspace.RunNet(pred_net)

    _ids = np.squeeze(workspace.FetchBlob('prediction'))

    restore_id_func, get_restore_id_grad_func = preproc.get_restore_id_func(
        preproc_param['scale'])
    ids = restore_id_func(_ids)
    return ids
Beispiel #2
0
    def predict_ids(self, vg, vd):
        # preproc the input
        vg = vg.astype(np.float32)
        vd = vd.astype(np.float32)
        if len(self.preproc_param) == 0:
            self.preproc_param = pickle.load(open(self.pickle_file_name, "rb"))
        dummy_ids = np.zeros(len(vg))
        preproc_data_arrays = preproc.dc_iv_preproc(
            vg,
            vd,
            dummy_ids,
            self.preproc_param['scale'],
            self.preproc_param['vg_shift'],
        )
        _preproc_data_arrays = [
            np.expand_dims(x, axis=1) for x in preproc_data_arrays
        ]
        workspace.FeedBlob('DBInput_train/sig_input', _preproc_data_arrays[0])
        workspace.FeedBlob('DBInput_train/tanh_input', _preproc_data_arrays[1])
        pred_net = self.net_store['pred_net']
        workspace.RunNet(pred_net)

        _ids = np.squeeze(schema.FetchRecord(self.pred).get())
        restore_id_func, _ = preproc.get_restore_id_func(
            self.preproc_param['scale'],
            self.preproc_param['vg_shift'],
        )
        ids = restore_id_func(_ids)
        return _ids, ids
Beispiel #3
0
    def predict_ids(self, vg, vd):
        # preproc the input
        vg = vg.astype(np.float32)
        vd = vd.astype(np.float32)
        if len(self.preproc_param) == 0:
            self.preproc_param = pickle.load(open(self.pickle_file_name, "rb"))
        dummy_ids = np.zeros(len(vg))
        preproc_data_arrays = [vg, vd, dummy_ids]
        if self.train_target == TrainTarget.ORIGIN:
            preproc_data_arrays = preproc.dc_iv_preproc(
                vg,
                vd,
                dummy_ids,
                self.preproc_param['scale'],
                self.preproc_param['vg_shift'],
            )

        _preproc_data_arrays = [
            np.expand_dims(x, axis=1) if x.ndim == 1 else x
            for x in preproc_data_arrays
        ]
        workspace.FeedBlob('DBInput_train/sig_input', _preproc_data_arrays[0])
        workspace.FeedBlob('DBInput_train/tanh_input', _preproc_data_arrays[1])

        if self.train_target == TrainTarget.ADJOINT:
            adjoint_input = np.ones((vg.shape[0], 1))
            workspace.FeedBlob('DBInput_train/adjoint_input', adjoint_input)

        pred_net = self.net_store['pred_net']
        workspace.RunNet(pred_net)

        _ids = np.squeeze(schema.FetchRecord(self.pred).get())
        ids = _ids
        if self.train_target == TrainTarget.ORIGIN:
            restore_id_func, _ = preproc.get_restore_id_func(
                self.preproc_param['scale'],
                self.preproc_param['vg_shift'],
            )
            ids = restore_id_func(_ids)

        return _ids, ids
Beispiel #4
0
def predict_ids_grads(model_name, vg, vd):
    workspace.ResetWorkspace()

    # preproc the input
    vg = vg.astype(np.float32)
    vd = vd.astype(np.float32)
    #if len(self.preproc_param) == 0:
    preproc_param = pickle.load(open(model_name + '_preproc_param.p', "rb"))
    dummy_ids = np.zeros(len(vg))
    preproc_data_arrays = preproc.dc_iv_preproc(
        vg,
        vd,
        dummy_ids,
        preproc_param['scale'],
        preproc_param['vg_shift'],
    )
    _preproc_data_arrays = [
        np.expand_dims(x, axis=1) for x in preproc_data_arrays
    ]

    workspace.FeedBlob('DBInput_train/sig_input', _preproc_data_arrays[0])
    workspace.FeedBlob('DBInput_train/tanh_input', _preproc_data_arrays[1])
    adjoint_input = np.ones((_preproc_data_arrays[0].shape[0], 1))
    workspace.FeedBlob('adjoint_input', adjoint_input)
    pred_net = exporter.load_net(model_name + '_init', model_name + '_predict')

    workspace.RunNet(pred_net)

    _ids = np.squeeze(workspace.FetchBlob('origin/Mul/origin_pred'))
    _sig_grad = np.squeeze(
        workspace.FetchBlob('adjoint/sig_fc_layer_0/output'))
    _tanh_grad = np.squeeze(
        workspace.FetchBlob('adjoint/tanh_fc_layer_0/output'))

    restore_id_func, get_restore_id_grad_func = preproc.get_restore_id_func(
        preproc_param['scale'])
    ids = restore_id_func(_ids)
    sig_grad, tanh_grad = get_restore_id_grad_func(_sig_grad, _tanh_grad)
    return ids, sig_grad, tanh_grad