首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DeepChem GraphConvodel (GNN)培训TypeError

DeepChem GraphConvodel (GNN)培训TypeError
EN

Stack Overflow用户
提问于 2021-04-29 10:49:46
回答 1查看 87关注 0票数 1

我是GNN的初学者,我正在尝试使用DeepChem的Tox21数据集来预测药物毒性的代码。它是一个包含12000个化合物的训练集和650个化合物的测试集。在调试和纠正此错误方面,我需要帮助:“TypeError:'NoneType‘对象不是可订阅的”,这是我在最后得到的。

下面是代码片段:

代码语言:javascript
复制
model = GraphConvModel(len(tox21_tasks), 
                   batch_size=32, 
                   mode='classification')

print("Fitting the model")

model.fit(train_dataset, nb_epoch=10)

这是我的错误:

代码语言:javascript
复制
    TypeError                                 Traceback (most recent call last)
<ipython-input-5-8088249b7fd6> in <module>
      4                        mode='classification')
      5 print("Fitting the model")
----> 6 model.fit(train_dataset, nb_epoch=10)

~\anaconda3\lib\site-packages\deepchem\models\keras_model.py in fit(self, dataset, nb_epoch, max_checkpoints_to_keep, checkpoint_interval, deterministic, restore, variables, loss, callbacks, all_losses)
    322             dataset, epochs=nb_epoch,
    323             deterministic=deterministic), max_checkpoints_to_keep,
--> 324         checkpoint_interval, restore, variables, loss, callbacks, all_losses)
    325 
    326   def fit_generator(self,

~\anaconda3\lib\site-packages\deepchem\models\keras_model.py in fit_generator(self, generator, max_checkpoints_to_keep, checkpoint_interval, restore, variables, loss, callbacks, all_losses)
    407         inputs = inputs[0]
    408 
--> 409       batch_loss = apply_gradient_for_batch(inputs, labels, weights, loss)
    410       current_step = self._global_step.numpy()
    411 

~\anaconda3\lib\site-packages\tensorflow_core\python\eager\def_function.py in __call__(self, *args, **kwds)
    455 
    456     tracing_count = self._get_tracing_count()
--> 457     result = self._call(*args, **kwds)
    458     if tracing_count == self._get_tracing_count():
    459       self._call_counter.called_without_tracing()

~\anaconda3\lib\site-packages\tensorflow_core\python\eager\def_function.py in _call(self, *args, **kwds)
    501       # This is the first call of __call__, so we have to initialize.
    502       initializer_map = object_identity.ObjectIdentityDictionary()
--> 503       self._initialize(args, kwds, add_initializers_to=initializer_map)
    504     finally:
    505       # At this point we know that the initialization is complete (or less

~\anaconda3\lib\site-packages\tensorflow_core\python\eager\def_function.py in _initialize(self, args, kwds, add_initializers_to)
    406     self._concrete_stateful_fn = (
    407         self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
--> 408             *args, **kwds))
    409 
    410     def invalid_creator_scope(*unused_args, **unused_kwds):

~\anaconda3\lib\site-packages\tensorflow_core\python\eager\function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
   1846     if self.input_signature:
   1847       args, kwargs = None, None
-> 1848     graph_function, _, _ = self._maybe_define_function(args, kwargs)
   1849     return graph_function
   1850 

~\anaconda3\lib\site-packages\tensorflow_core\python\eager\function.py in _maybe_define_function(self, args, kwargs)
   2148         graph_function = self._function_cache.primary.get(cache_key, None)
   2149         if graph_function is None:
-> 2150           graph_function = self._create_graph_function(args, kwargs)
   2151           self._function_cache.primary[cache_key] = graph_function
   2152         return graph_function, args, kwargs

~\anaconda3\lib\site-packages\tensorflow_core\python\eager\function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes)
   2039             arg_names=arg_names,
   2040             override_flat_arg_shapes=override_flat_arg_shapes,
-> 2041             capture_by_value=self._capture_by_value),
   2042         self._function_attributes,
   2043         # Tell the ConcreteFunction to clean up its graph once it goes out of

~\anaconda3\lib\site-packages\tensorflow_core\python\framework\func_graph.py in func_graph_from_py_func(name, python_func, args, kwargs, signature, func_graph, autograph, autograph_options, add_control_dependencies, arg_names, op_return_value, collections, capture_by_value, override_flat_arg_shapes)
    913                                           converted_func)
    914 
--> 915       func_outputs = python_func(*func_args, **func_kwargs)
    916 
    917       # invariant: `func_outputs` contains only Tensors, CompositeTensors,

~\anaconda3\lib\site-packages\tensorflow_core\python\eager\def_function.py in wrapped_fn(*args, **kwds)
    356         # __wrapped__ allows AutoGraph to swap in a converted function. We give
    357         # the function a weak reference to itself to avoid a reference cycle.
--> 358         return weak_wrapped_fn().__wrapped__(*args, **kwds)
    359     weak_wrapped_fn = weakref.ref(wrapped_fn)
    360 

~\anaconda3\lib\site-packages\tensorflow_core\python\framework\func_graph.py in wrapper(*args, **kwargs)
    903           except Exception as e:  # pylint:disable=broad-except
    904             if hasattr(e, "ag_error_metadata"):
--> 905               raise e.ag_error_metadata.to_exception(e)
    906             else:
    907               raise

TypeError: in converted code:
    relative to C:\Users\Madiha\anaconda3\lib\site-packages:

    deepchem\models\keras_model.py:474 apply_gradient_for_batch  *
        grads = tape.gradient(batch_loss, vars)
    tensorflow_core\python\eager\backprop.py:1014 gradient
        unconnected_gradients=unconnected_gradients)
    tensorflow_core\python\eager\imperative_grad.py:76 imperative_grad
        compat.as_str(unconnected_gradients.value))
    tensorflow_core\python\eager\backprop.py:138 _gradient_function
        return grad_fn(mock_op, *out_grads)
    tensorflow_core\python\ops\math_grad.py:455 _UnsortedSegmentMaxGrad
        return _UnsortedSegmentMinOrMaxGrad(op, grad)
    tensorflow_core\python\ops\math_grad.py:432 _UnsortedSegmentMinOrMaxGrad
        _GatherDropNegatives(op.outputs[0], op.inputs[1])

    TypeError: 'NoneType' object is not subscriptable
EN

回答 1

Stack Overflow用户

发布于 2021-04-29 19:36:26

作为建议,请查看DeepChem网站上的一些示例。下面是一个代码,它可以工作:

代码语言:javascript
复制
tasks, datasets, transformers = dc.molnet.load_tox21(featurizer='GraphConv')
train_dataset, valid_dataset, test_dataset = datasets

model = dc.models.GraphConvModel(len(tasks), 
                   batch_size=32, 
                   mode='classification')

print("Fitting the model")

model.fit(train_dataset)

希望是为你工作!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67315879

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档