当前位置: 首页>>代码示例>>Python>>正文


Python TensorGraph.load_from_dir方法代码示例

本文整理汇总了Python中deepchem.models.TensorGraph.load_from_dir方法的典型用法代码示例。如果您正苦于以下问题:Python TensorGraph.load_from_dir方法的具体用法?Python TensorGraph.load_from_dir怎么用?Python TensorGraph.load_from_dir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在deepchem.models.TensorGraph的用法示例。


在下文中一共展示了TensorGraph.load_from_dir方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_graph_conv_atom_features

# 需要导入模块: from deepchem.models import TensorGraph [as 别名]
# 或者: from deepchem.models.TensorGraph import load_from_dir [as 别名]
  def test_graph_conv_atom_features(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'Raw', num_tasks=1)

    atom_feature_name = 'feature'
    y = []
    for mol in dataset.X:
      atom_features = []
      for atom in mol.GetAtoms():
        val = np.random.normal()
        mol.SetProp("atom %08d %s" % (atom.GetIdx(), atom_feature_name),
                    str(val))
        atom_features.append(np.random.normal())
      y.append([np.sum(atom_features)])

    featurizer = ConvMolFeaturizer(atom_properties=[atom_feature_name])
    X = featurizer.featurize(dataset.X)
    dataset = dc.data.NumpyDataset(X, np.array(y))
    batch_size = 50
    model = GraphConvModel(
        len(tasks),
        number_atom_features=featurizer.feature_length(),
        batch_size=batch_size,
        mode='regression')

    model.fit(dataset, nb_epoch=1)
    y_pred1 = model.predict(dataset)
    model.save()

    model2 = TensorGraph.load_from_dir(model.model_dir)
    y_pred2 = model2.predict(dataset)
    self.assertTrue(np.allclose(y_pred1, y_pred2))
开发者ID:ktaneishi,项目名称:deepchem,代码行数:34,代码来源:test_graph_models.py

示例2: test_weave_regression_model

# 需要导入模块: from deepchem.models import TensorGraph [as 别名]
# 或者: from deepchem.models.TensorGraph import load_from_dir [as 别名]
  def test_weave_regression_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'Weave')

    model = WeaveModel(len(tasks), mode='regression')

    model.fit(dataset, nb_epoch=80)
    scores = model.evaluate(dataset, [metric], transformers)
    assert all(s < 0.1 for s in scores['mean_absolute_error'])

    model.save()
    model = TensorGraph.load_from_dir(model.model_dir)
    scores2 = model.evaluate(dataset, [metric], transformers)
    assert np.allclose(scores['mean_absolute_error'],
                       scores2['mean_absolute_error'])
开发者ID:ktaneishi,项目名称:deepchem,代码行数:17,代码来源:test_graph_models.py

示例3: test_weave_model

# 需要导入模块: from deepchem.models import TensorGraph [as 别名]
# 或者: from deepchem.models.TensorGraph import load_from_dir [as 别名]
  def test_weave_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'classification', 'Weave')

    model = WeaveModel(len(tasks), mode='classification')

    model.fit(dataset, nb_epoch=50)
    scores = model.evaluate(dataset, [metric], transformers)
    assert scores['mean-roc_auc_score'] >= 0.9

    model.save()
    model = TensorGraph.load_from_dir(model.model_dir)
    scores2 = model.evaluate(dataset, [metric], transformers)
    assert np.allclose(scores['mean-roc_auc_score'],
                       scores2['mean-roc_auc_score'])
开发者ID:ktaneishi,项目名称:deepchem,代码行数:17,代码来源:test_graph_models.py

示例4: test_graph_conv_model

# 需要导入模块: from deepchem.models import TensorGraph [as 别名]
# 或者: from deepchem.models.TensorGraph import load_from_dir [as 别名]
  def test_graph_conv_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'classification', 'GraphConv')

    batch_size = 50
    model = GraphConvModel(
        len(tasks), batch_size=batch_size, mode='classification')

    model.fit(dataset, nb_epoch=10)
    scores = model.evaluate(dataset, [metric], transformers)
    assert scores['mean-roc_auc_score'] >= 0.9

    model.save()
    model = TensorGraph.load_from_dir(model.model_dir)
    scores2 = model.evaluate(dataset, [metric], transformers)
    assert np.allclose(scores['mean-roc_auc_score'],
                       scores2['mean-roc_auc_score'])
开发者ID:ktaneishi,项目名称:deepchem,代码行数:19,代码来源:test_graph_models.py

示例5: test_change_loss_function

# 需要导入模块: from deepchem.models import TensorGraph [as 别名]
# 或者: from deepchem.models.TensorGraph import load_from_dir [as 别名]
  def test_change_loss_function(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'GraphConv', num_tasks=1)

    batch_size = 50
    model = GraphConvModel(len(tasks), batch_size=batch_size, mode='regression')

    model.fit(dataset, nb_epoch=1)
    model.save()

    model2 = TensorGraph.load_from_dir(model.model_dir, restore=False)
    dummy_label = model2.labels[-1]
    dummy_ouput = model2.outputs[-1]
    loss = ReduceSum(L2Loss(in_layers=[dummy_label, dummy_ouput]))
    module = model2.create_submodel(loss=loss)
    model2.restore()
    model2.fit(dataset, nb_epoch=1, submodel=module)
开发者ID:ktaneishi,项目名称:deepchem,代码行数:19,代码来源:test_graph_models.py

示例6: test_graph_conv_regression_model

# 需要导入模块: from deepchem.models import TensorGraph [as 别名]
# 或者: from deepchem.models.TensorGraph import load_from_dir [as 别名]
  def test_graph_conv_regression_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'GraphConv')

    batch_size = 50
    model = GraphConvModel(len(tasks), batch_size=batch_size, mode='regression')

    model.fit(dataset, nb_epoch=100)
    scores = model.evaluate(dataset, [metric], transformers)
    assert all(s < 0.1 for s in scores['mean_absolute_error'])

    model.save()
    model = TensorGraph.load_from_dir(model.model_dir)
    scores2 = model.evaluate(dataset, [metric], transformers)
    assert np.allclose(
        scores['mean_absolute_error'],
        scores2['mean_absolute_error'],
        rtol=1e-4)
开发者ID:ktaneishi,项目名称:deepchem,代码行数:20,代码来源:test_graph_models.py

示例7: test_dag_model

# 需要导入模块: from deepchem.models import TensorGraph [as 别名]
# 或者: from deepchem.models.TensorGraph import load_from_dir [as 别名]
  def test_dag_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'classification', 'GraphConv')

    max_atoms = max([mol.get_num_atoms() for mol in dataset.X])
    transformer = dc.trans.DAGTransformer(max_atoms=max_atoms)
    dataset = transformer.transform(dataset)

    model = DAGModel(
        len(tasks), max_atoms=max_atoms, mode='classification', use_queue=False)

    model.fit(dataset, nb_epoch=10)
    scores = model.evaluate(dataset, [metric], transformers)
    assert scores['mean-roc_auc_score'] >= 0.9

    model.save()
    model = TensorGraph.load_from_dir(model.model_dir)
    scores2 = model.evaluate(dataset, [metric], transformers)
    assert np.allclose(scores['mean-roc_auc_score'],
                       scores2['mean-roc_auc_score'])
开发者ID:ktaneishi,项目名称:deepchem,代码行数:22,代码来源:test_graph_models.py

示例8: test_mpnn_regression_model

# 需要导入模块: from deepchem.models import TensorGraph [as 别名]
# 或者: from deepchem.models.TensorGraph import load_from_dir [as 别名]
  def test_mpnn_regression_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'Weave')

    model = MPNNModel(
        len(tasks),
        mode='regression',
        n_hidden=75,
        n_atom_feat=75,
        n_pair_feat=14,
        T=1,
        M=1)

    model.fit(dataset, nb_epoch=50)
    scores = model.evaluate(dataset, [metric], transformers)
    assert all(s < 0.1 for s in scores['mean_absolute_error'])

    model.save()
    model = TensorGraph.load_from_dir(model.model_dir)
    scores2 = model.evaluate(dataset, [metric], transformers)
    assert np.allclose(scores['mean_absolute_error'],
                       scores2['mean_absolute_error'])
开发者ID:ktaneishi,项目名称:deepchem,代码行数:24,代码来源:test_graph_models.py

示例9: test_mpnn_model

# 需要导入模块: from deepchem.models import TensorGraph [as 别名]
# 或者: from deepchem.models.TensorGraph import load_from_dir [as 别名]
  def test_mpnn_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'classification', 'Weave')

    model = MPNNModel(
        len(tasks),
        mode='classification',
        n_hidden=75,
        n_atom_feat=75,
        n_pair_feat=14,
        T=1,
        M=1)

    model.fit(dataset, nb_epoch=20)
    scores = model.evaluate(dataset, [metric], transformers)
    assert scores['mean-roc_auc_score'] >= 0.9

    model.save()
    model = TensorGraph.load_from_dir(model.model_dir)
    scores2 = model.evaluate(dataset, [metric], transformers)
    assert np.allclose(scores['mean-roc_auc_score'],
                       scores2['mean-roc_auc_score'])
开发者ID:ktaneishi,项目名称:deepchem,代码行数:24,代码来源:test_graph_models.py

示例10: test_save_load

# 需要导入模块: from deepchem.models import TensorGraph [as 别名]
# 或者: from deepchem.models.TensorGraph import load_from_dir [as 别名]
  def test_save_load(self):
    """Test SaScoreModel anc be saved and loaded"""
    n_samples = 10
    n_features = 3
    n_tasks = 1

    # Create a dataset and an input function for processing it.

    np.random.seed(123)
    X = np.random.rand(n_samples, 2, n_features)
    y = np.zeros((n_samples, n_tasks))
    dataset = deepchem.data.NumpyDataset(X, y)

    model = deepchem.models.ScScoreModel(n_features, dropouts=0)

    model.fit(dataset, nb_epoch=1)
    pred1 = model.predict(dataset)

    model.save()
    model = TensorGraph.load_from_dir(model.model_dir)

    pred2 = model.predict(dataset)
    for m1, m2 in zip(pred1, pred2):
      self.assertTrue(np.all(m1 == m2))
开发者ID:AhlamMD,项目名称:deepchem,代码行数:26,代码来源:test_sascore.py

示例11: test_dag_regression_model

# 需要导入模块: from deepchem.models import TensorGraph [as 别名]
# 或者: from deepchem.models.TensorGraph import load_from_dir [as 别名]
  def test_dag_regression_model(self):
    tasks, dataset, transformers, metric = self.get_dataset(
        'regression', 'GraphConv')

    max_atoms = max([mol.get_num_atoms() for mol in dataset.X])
    transformer = dc.trans.DAGTransformer(max_atoms=max_atoms)
    dataset = transformer.transform(dataset)

    model = DAGModel(
        len(tasks),
        max_atoms=max_atoms,
        mode='regression',
        learning_rate=0.003,
        use_queue=False)

    model.fit(dataset, nb_epoch=100)
    scores = model.evaluate(dataset, [metric], transformers)
    assert all(s < 0.15 for s in scores['mean_absolute_error'])

    model.save()
    model = TensorGraph.load_from_dir(model.model_dir)
    scores2 = model.evaluate(dataset, [metric], transformers)
    assert np.allclose(scores['mean_absolute_error'],
                       scores2['mean_absolute_error'])
开发者ID:ktaneishi,项目名称:deepchem,代码行数:26,代码来源:test_graph_models.py


注:本文中的deepchem.models.TensorGraph.load_from_dir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。