图像序列的TF数据集作为TimeDistributed CNN(CNN-LSTM)的输入

时间:2019-09-05 11:55:07

标签: python-3.x tensorflow tensorflow-datasets

我有一组图像(以jpg表示的视频帧),并且想要创建一个CNN-LSTM模型来对每个图像进行分类(很多到很多LSTM)。如何创建Tensorflow 2数据集作为模型的输入?

一个视频包含约10,000至40,000帧,此序列对于LSTM而言仍太长而无法保留有关先前状态的信息。我想将视频切成100个帧的序列,并对其进行单独分类。

这是我的TF模型(我正在使用TF集线器进行预训练的图像嵌入):

feature_extractor_url = "https://tfhub.dev/google/tf2-preview/inception_v3/feature_vector/4"
    model = tf.keras.Sequential([
        tf.keras.layers.TimeDistributed(hub.KerasLayer(feature_extractor_url, input_shape=(width, height, 3), output_shape=[2048],
                       trainable=True), batch_input_shape=(100, None, 299, 299, 3)),
        tf.keras.layers.Bidirectional(tf.keras.layers.GRU(1024, return_sequences=True)),
        tf.keras.layers.Bidirectional(tf.keras.layers.GRU(512, return_sequences=True)),
        tf.keras.layers.Bidirectional(tf.keras.layers.GRU(256, return_sequences=True)),
        tf.keras.layers.Dense(2, activation='softmax')
    ])

    model.compile(
        optimizer=tf.keras.optimizers.Adam(lr=learning_rate),
        loss=tf.keras.losses.CategoricalCrossentropy(label_smoothing=label_smoothing),
        metrics=['accuracy'])

这是我加载数据的方式:

def parse_image(file_path):
    image = tf.io.read_file(file_path)
    image = tf.image.decode_jpeg(image, channels=3)
    image = tf.image.convert_image_dtype(image, tf.float32)
    image = tf.image.resize(image, [constants.width, constants.height])
    image /= 255.0
    return image


def get_image_ds(dir_name: str, sequence_length: int):
    data_root = constants.data_root
    data_root = pathlib.Path(str(data_root) + dir_name)
    list_ds = tf.data.Dataset.list_files(str(data_root / 'all/*'), shuffle=False)
    image_data = list_ds.map(parse_image)
    return image_data.batch(sequence_length, drop_remainder=True)\


def get_label_ds(filename: str, label_to_index: Dict[str, int]):
    with open(filename, 'r', encoding='utf8') as file:
        labels = [line.split(' ')[1].replace('\n', '') for line in file]
    all_image_labels = [label_to_index[label_name] for label_name in labels]
    label_ds = tf.data.Dataset.from_tensor_slices(all_image_labels)
    return label_ds, len(all_image_labels)


def get_tf_dataset(sequence_length: int, batch_size: int):
    label_names = ['selected', 'not_selected']
    label_to_index = dict((name, index) for index, name in enumerate(label_names))

    train_image_data = get_image_ds('/train', sequence_length)
    train_labels, n_train_data = get_label_ds('data/train.txt', label_to_index)
    train_ds = tf.data.Dataset.zip((train_image_data, train_labels))\
        .batch(batch_size)\
        .prefetch(buffer_size=AUTOTUNE)

    test_image_data = get_image_ds('/test', sequence_length)
    test_labels, _ = get_label_ds('data/test.txt', label_to_index)
    test_ds = tf.data.Dataset.zip((test_image_data, test_labels))\
        .batch(batch_size)\
        .prefetch(buffer_size=AUTOTUNE)

    val_image_data = get_image_ds('/val', sequence_length)
    val_labels, _ = get_label_ds('data/val.txt', label_to_index)
    val_ds = tf.data.Dataset.zip((val_image_data, val_labels))\
        .batch(batch_size)\
        .prefetch(buffer_size=AUTOTUNE)

在执行model.fit之后,Tensorflow现在引发NotImplementedError:

hist = model.fit(
    train_image_data,
    epochs=5,
    steps_per_epoch=steps_per_epoch,
    validation_data=val_image_data,
    validation_steps=100,
).history

错误消息:

Train for 1266.0 steps, validate for 100 steps
Epoch 1/5

   1/1266 [..............................] - ETA: 10:50
---------------------------------------------------------------------------

NotImplementedError                       Traceback (most recent call last)

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in on_epoch(self, epoch, mode)
    679     try:
--> 680       yield epoch_logs
    681     finally:

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in fit(self, model, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, **kwargs)
    323                 training_context=training_context,
--> 324                 total_epochs=epochs)
    325             cbks.make_logs(model, epoch_logs, training_result, ModeKeys.TRAIN)

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in run_one_epoch(model, iterator, execution_function, dataset_size, batch_size, strategy, steps_per_epoch, num_samples, mode, training_context, total_epochs)
    122       try:
--> 123         batch_outs = execution_function(iterator)
    124       except (StopIteration, errors.OutOfRangeError):

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py in execution_function(input_fn)
     85     return nest.map_structure(_non_none_constant_value,
---> 86                               distributed_function(input_fn))
     87 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\def_function.py in __call__(self, *args, **kwds)
    426     initializer_map = object_identity.ObjectIdentityDictionary()
--> 427     self._initialize(args, kwds, add_initializers_to=initializer_map)
    428     if self._created_variables:

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\def_function.py in _initialize(self, args, kwds, add_initializers_to)
    369         self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
--> 370             *args, **kwds))
    371 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
   1846       args, kwargs = None, None
-> 1847     graph_function, _, _ = self._maybe_define_function(args, kwargs)
   1848     return graph_function

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\function.py in _maybe_define_function(self, args, kwargs)
   2146         if graph_function is None:
-> 2147           graph_function = self._create_graph_function(args, kwargs)
   2148           self._function_cache.primary[cache_key] = graph_function

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes)
   2037             override_flat_arg_shapes=override_flat_arg_shapes,
-> 2038             capture_by_value=self._capture_by_value),
   2039         self._function_attributes,

c:\users\yanick\code\pycharmprojects\avisec\venv\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)
    914 
--> 915       func_outputs = python_func(*func_args, **func_kwargs)
    916 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\def_function.py in wrapped_fn(*args, **kwds)
    319         # the function a weak reference to itself to avoid a reference cycle.
--> 320         return weak_wrapped_fn().__wrapped__(*args, **kwds)
    321     weak_wrapped_fn = weakref.ref(wrapped_fn)

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py in distributed_function(input_iterator)
     72     outputs = strategy.experimental_run_v2(
---> 73         per_replica_function, args=(model, x, y, sample_weights))
     74     # Out of PerReplica outputs reduce or pick values to return.

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\distribute\distribute_lib.py in experimental_run_v2(self, fn, args, kwargs)
    759                                 convert_by_default=False)
--> 760       return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
    761 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\distribute\distribute_lib.py in call_for_each_replica(self, fn, args, kwargs)
   1786     with self._container_strategy().scope():
-> 1787       return self._call_for_each_replica(fn, args, kwargs)
   1788 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\distribute\distribute_lib.py in _call_for_each_replica(self, fn, args, kwargs)
   2131         replica_id_in_sync_group=constant_op.constant(0, dtypes.int32)):
-> 2132       return fn(*args, **kwargs)
   2133 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\autograph\impl\api.py in wrapper(*args, **kwargs)
    291     with ag_ctx.ControlStatusCtx(status=ag_ctx.Status.DISABLED):
--> 292       return func(*args, **kwargs)
    293 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py in train_on_batch(model, x, y, sample_weight, class_weight, reset_metrics)
    263       sample_weights=sample_weights,
--> 264       output_loss_metrics=model._output_loss_metrics)
    265 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_eager.py in train_on_batch(model, inputs, targets, sample_weights, output_loss_metrics)
    310           training=True,
--> 311           output_loss_metrics=output_loss_metrics))
    312   if not isinstance(outs, list):

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_eager.py in _process_single_batch(model, inputs, targets, output_loss_metrics, sample_weights, training)
    251               sample_weights=sample_weights,
--> 252               training=training))
    253       if total_loss is None:

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_eager.py in _model_loss(model, inputs, targets, output_loss_metrics, sample_weights, training)
    126 
--> 127   outs = model(inputs, **kwargs)
    128   outs = nest.flatten(outs)

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py in __call__(self, inputs, *args, **kwargs)
    806                 else:
--> 807                   outputs = call_fn(cast_inputs, *args, **kwargs)
    808 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\sequential.py in call(self, inputs, training, mask)
    254         self._init_graph_network(self.inputs, self.outputs, name=self.name)
--> 255       return super(Sequential, self).call(inputs, training=training, mask=mask)
    256 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\network.py in call(self, inputs, training, mask)
    696 
--> 697     return self._run_internal_graph(inputs, training=training, mask=mask)
    698 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\network.py in _run_internal_graph(self, inputs, training, mask)
    841           # Compute outputs.
--> 842           output_tensors = layer(computed_tensors, **kwargs)
    843 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py in __call__(self, inputs, *args, **kwargs)
    806                 else:
--> 807                   outputs = call_fn(cast_inputs, *args, **kwargs)
    808 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\layers\wrappers.py in call(self, inputs, training, mask)
    255       # Shape: (num_samples, timesteps, ...)
--> 256       output_shape = self.compute_output_shape(input_shape).as_list()
    257       output_shape = self._get_shape_tuple(

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\layers\wrappers.py in compute_output_shape(self, input_shape)
    209                                                  input_shape[2:])
--> 210     child_output_shape = self.layer.compute_output_shape(child_input_shape)
    211     if not isinstance(child_output_shape, tensor_shape.TensorShape):

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py in compute_output_shape(self, input_shape)
    598       return nest.map_structure(lambda t: t.shape, outputs)
--> 599     raise NotImplementedError
    600 

NotImplementedError: 


During handling of the above exception, another exception occurred:

NotImplementedError                       Traceback (most recent call last)

<ipython-input-8-6bf7fd9bb8ab> in <module>
      5     callbacks=[tensorboard_callback, cm_callback],
      6     validation_data=val_image_data,
----> 7     validation_steps=100,
      8 ).history

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
    732         max_queue_size=max_queue_size,
    733         workers=workers,
--> 734         use_multiprocessing=use_multiprocessing)
    735 
    736   def evaluate(self,

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in fit(self, model, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, **kwargs)
    370                       total_epochs=1)
    371                   cbks.make_logs(model, epoch_logs, eval_result, ModeKeys.TEST,
--> 372                                  prefix='val_')
    373 
    374     return model.history

~\AppData\Local\Programs\Python\Python36\Lib\contextlib.py in __exit__(self, type, value, traceback)
     97                 value = type()
     98             try:
---> 99                 self.gen.throw(type, value, traceback)
    100             except StopIteration as exc:
    101                 # Suppress StopIteration *unless* it's the same exception that

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in on_epoch(self, epoch, mode)
    682       if mode == ModeKeys.TRAIN:
    683         # Epochs only apply to `fit`.
--> 684         self.callbacks.on_epoch_end(epoch, epoch_logs)
    685       self.progbar.on_epoch_end(epoch, epoch_logs)
    686 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\callbacks.py in on_epoch_end(self, epoch, logs)
    295     logs = logs or {}
    296     for callback in self.callbacks:
--> 297       callback.on_epoch_end(epoch, logs)
    298 
    299   def on_train_batch_begin(self, batch, logs=None):

<ipython-input-6-ce1724da9329> in log_confusion_matrix(epoch, logs)
      6 def log_confusion_matrix(epoch, logs):
      7     # Use the model to predict the values from the validation dataset.
----> 8     test_pred_raw = model.predict(test_image_data)
      9     test_pred = np.argmax(test_pred_raw, axis=1)
     10 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training.py in predict(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
    913         max_queue_size=max_queue_size,
    914         workers=workers,
--> 915         use_multiprocessing=use_multiprocessing)
    916 
    917   def reset_metrics(self):

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in predict(self, model, x, batch_size, verbose, steps, callbacks, **kwargs)
    460     return self._model_iteration(
    461         model, ModeKeys.PREDICT, x=x, batch_size=batch_size, verbose=verbose,
--> 462         steps=steps, callbacks=callbacks, **kwargs)
    463 
    464 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in _model_iteration(self, model, mode, x, y, batch_size, verbose, sample_weight, steps, callbacks, **kwargs)
    442               mode=mode,
    443               training_context=training_context,
--> 444               total_epochs=1)
    445           cbks.make_logs(model, epoch_logs, result, mode)
    446 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2.py in run_one_epoch(model, iterator, execution_function, dataset_size, batch_size, strategy, steps_per_epoch, num_samples, mode, training_context, total_epochs)
    121         step=step, mode=mode, size=current_batch_size) as batch_logs:
    122       try:
--> 123         batch_outs = execution_function(iterator)
    124       except (StopIteration, errors.OutOfRangeError):
    125         # TODO(kaftan): File bug about tf function and errors.OutOfRangeError?

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py in execution_function(input_fn)
     84     # `numpy` translates Tensors to values in Eager mode.
     85     return nest.map_structure(_non_none_constant_value,
---> 86                               distributed_function(input_fn))
     87 
     88   return execution_function

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\def_function.py in __call__(self, *args, **kwds)
    425     # This is the first call of __call__, so we have to initialize.
    426     initializer_map = object_identity.ObjectIdentityDictionary()
--> 427     self._initialize(args, kwds, add_initializers_to=initializer_map)
    428     if self._created_variables:
    429       try:

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\def_function.py in _initialize(self, args, kwds, add_initializers_to)
    368     self._concrete_stateful_fn = (
    369         self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
--> 370             *args, **kwds))
    371 
    372     def invalid_creator_scope(*unused_args, **unused_kwds):

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
   1845     if self.input_signature:
   1846       args, kwargs = None, None
-> 1847     graph_function, _, _ = self._maybe_define_function(args, kwargs)
   1848     return graph_function
   1849 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\function.py in _maybe_define_function(self, args, kwargs)
   2145         graph_function = self._function_cache.primary.get(cache_key, None)
   2146         if graph_function is None:
-> 2147           graph_function = self._create_graph_function(args, kwargs)
   2148           self._function_cache.primary[cache_key] = graph_function
   2149         return graph_function, args, kwargs

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes)
   2036             arg_names=arg_names,
   2037             override_flat_arg_shapes=override_flat_arg_shapes,
-> 2038             capture_by_value=self._capture_by_value),
   2039         self._function_attributes,
   2040         # Tell the ConcreteFunction to clean up its graph once it goes out of

c:\users\yanick\code\pycharmprojects\avisec\venv\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,

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\eager\def_function.py in wrapped_fn(*args, **kwds)
    318         # __wrapped__ allows AutoGraph to swap in a converted function. We give
    319         # the function a weak reference to itself to avoid a reference cycle.
--> 320         return weak_wrapped_fn().__wrapped__(*args, **kwds)
    321     weak_wrapped_fn = weakref.ref(wrapped_fn)
    322 

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py in distributed_function(input_iterator)
     71     strategy = distribution_strategy_context.get_strategy()
     72     outputs = strategy.experimental_run_v2(
---> 73         per_replica_function, args=(model, x, y, sample_weights))
     74     # Out of PerReplica outputs reduce or pick values to return.
     75     all_outputs = dist_utils.unwrap_output_dict(

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\distribute\distribute_lib.py in experimental_run_v2(self, fn, args, kwargs)
    758       fn = autograph.tf_convert(fn, ag_ctx.control_status_ctx(),
    759                                 convert_by_default=False)
--> 760       return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
    761 
    762   def reduce(self, reduce_op, value, axis):

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\distribute\distribute_lib.py in call_for_each_replica(self, fn, args, kwargs)
   1785       kwargs = {}
   1786     with self._container_strategy().scope():
-> 1787       return self._call_for_each_replica(fn, args, kwargs)
   1788 
   1789   def _call_for_each_replica(self, fn, args, kwargs):

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\distribute\distribute_lib.py in _call_for_each_replica(self, fn, args, kwargs)
   2130         self._container_strategy(),
   2131         replica_id_in_sync_group=constant_op.constant(0, dtypes.int32)):
-> 2132       return fn(*args, **kwargs)
   2133 
   2134   def _reduce_to(self, reduce_op, value, destinations):

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\autograph\impl\api.py in wrapper(*args, **kwargs)
    290   def wrapper(*args, **kwargs):
    291     with ag_ctx.ControlStatusCtx(status=ag_ctx.Status.DISABLED):
--> 292       return func(*args, **kwargs)
    293 
    294   if inspect.isfunction(func) or inspect.ismethod(func):

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py in _predict_on_batch(***failed resolving arguments***)
    160     def _predict_on_batch(model, x, y=None, sample_weights=None):
    161       del y, sample_weights
--> 162       return predict_on_batch(model, x)
    163 
    164     func = _predict_on_batch

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\training_v2_utils.py in predict_on_batch(model, x)
    368 
    369   with backend.eager_learning_phase_scope(0):
--> 370     return model(inputs)  # pylint: disable=not-callable

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py in __call__(self, inputs, *args, **kwargs)
    805                     outputs = base_layer_utils.mark_as_return(outputs, acd)
    806                 else:
--> 807                   outputs = call_fn(cast_inputs, *args, **kwargs)
    808 
    809             except errors.OperatorNotAllowedInGraphError as e:

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\sequential.py in call(self, inputs, training, mask)
    253       if not self.built:
    254         self._init_graph_network(self.inputs, self.outputs, name=self.name)
--> 255       return super(Sequential, self).call(inputs, training=training, mask=mask)
    256 
    257     outputs = inputs  # handle the corner case where self.layers is empty

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\network.py in call(self, inputs, training, mask)
    695                                 ' implement a `call` method.')
    696 
--> 697     return self._run_internal_graph(inputs, training=training, mask=mask)
    698 
    699   def compute_output_shape(self, input_shape):

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\network.py in _run_internal_graph(self, inputs, training, mask)
    840 
    841           # Compute outputs.
--> 842           output_tensors = layer(computed_tensors, **kwargs)
    843 
    844           # Update tensor_dict.

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py in __call__(self, inputs, *args, **kwargs)
    805                     outputs = base_layer_utils.mark_as_return(outputs, acd)
    806                 else:
--> 807                   outputs = call_fn(cast_inputs, *args, **kwargs)
    808 
    809             except errors.OperatorNotAllowedInGraphError as e:

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\layers\wrappers.py in call(self, inputs, training, mask)
    254       y = self.layer(inputs, **kwargs)
    255       # Shape: (num_samples, timesteps, ...)
--> 256       output_shape = self.compute_output_shape(input_shape).as_list()
    257       output_shape = self._get_shape_tuple(
    258           (-1, input_length), y, 1, output_shape[2:])

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\layers\wrappers.py in compute_output_shape(self, input_shape)
    208     child_input_shape = tensor_shape.TensorShape([input_shape[0]] +
    209                                                  input_shape[2:])
--> 210     child_output_shape = self.layer.compute_output_shape(child_input_shape)
    211     if not isinstance(child_output_shape, tensor_shape.TensorShape):
    212       child_output_shape = tensor_shape.TensorShape(child_output_shape)

c:\users\yanick\code\pycharmprojects\avisec\venv\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py in compute_output_shape(self, input_shape)
    597                                       'layer (%s).' % self.__class__.__name__)
    598       return nest.map_structure(lambda t: t.shape, outputs)
--> 599     raise NotImplementedError
    600 
    601   @doc_controls.for_subclass_implementers

NotImplementedError: 
```

0 个答案:

没有答案