Tensorflow 无法在keras中使用landmarks\u分类器\u oceania模型检测希格斯玻色子粒子?

Tensorflow 无法在keras中使用landmarks\u分类器\u oceania模型检测希格斯玻色子粒子?,tensorflow,keras,deep-learning,tensorflow-hub,Tensorflow,Keras,Deep Learning,Tensorflow Hub,我试图看看是否可以使用迁移学习进行检测,但我无法理解错误消息。 我想知道这是否与所提到的模型是为计算机视觉设计的这一事实有关,所以它只适用于计算机视觉(我不认为是这样的,但任何输入都值得赞赏) 这是代码和错误信息 import tensorflow.compat.v2 as tf import tensorflow_hub as hub m = hub.KerasLayer('https://tfhub.dev/google/on_device_vision/classifier/landma

我试图看看是否可以使用迁移学习进行检测,但我无法理解错误消息。 我想知道这是否与所提到的模型是为计算机视觉设计的这一事实有关,所以它只适用于计算机视觉(我不认为是这样的,但任何输入都值得赞赏) 这是代码和错误信息

import tensorflow.compat.v2 as tf
import tensorflow_hub as hub

m = hub.KerasLayer('https://tfhub.dev/google/on_device_vision/classifier/landmarks_classifier_oceania_antarctica_V1/1')
m = tf.keras.Sequential([
    m,
    tf.keras.layers.Dense(2, activation='softmax'),
])


m.compile(loss = 'binary_crossentropy',  
   optimizer = 'adam', metrics = ['accuracy','binary_accuracy'])
history = m.fit(ds_train,validation_data=ds_valid, epochs =12 ,steps_per_epoch=13)
错误:

ValueError                                Traceback (most recent call last)
<ipython-input-20-0c5a3b4a3d55> in <module>
     11 m.compile(loss = 'binary_crossentropy',  
     12    optimizer = 'adam', metrics = ['accuracy','binary_accuracy'])
---> 13 history = m.fit(ds_train,validation_data=ds_valid, epochs =12 ,steps_per_epoch=13)

/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
     64   def _method_wrapper(self, *args, **kwargs):
     65     if not self._in_multi_worker_mode():  # pylint: disable=protected-access
---> 66       return method(self, *args, **kwargs)
     67 
     68     # Running inside `run_distribute_coordinator` already.

/opt/conda/lib/python3.7/site-packages/tensorflow/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_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
    846                 batch_size=batch_size):
    847               callbacks.on_train_batch_begin(step)
--> 848               tmp_logs = train_function(iterator)
    849               # Catch OutOfRangeError for Datasets of unknown size.
    850               # This blocks until the batch has finished executing.

/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds)
    578         xla_context.Exit()
    579     else:
--> 580       result = self._call(*args, **kwds)
    581 
    582     if tracing_count == self._get_tracing_count():

/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
    625       # This is the first call of __call__, so we have to initialize.
    626       initializers = []
--> 627       self._initialize(args, kwds, add_initializers_to=initializers)
    628     finally:
    629       # At this point we know that the initialization is complete (or less

/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in _initialize(self, args, kwds, add_initializers_to)
    504     self._concrete_stateful_fn = (
    505         self._stateful_fn._get_concrete_function_internal_garbage_collected(  # pylint: disable=protected-access
--> 506             *args, **kwds))
    507 
    508     def invalid_creator_scope(*unused_args, **unused_kwds):

/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
   2444       args, kwargs = None, None
   2445     with self._lock:
-> 2446       graph_function, _, _ = self._maybe_define_function(args, kwargs)
   2447     return graph_function
   2448 

/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/function.py in _maybe_define_function(self, args, kwargs)
   2775 
   2776       self._function_cache.missed.add(call_context_key)
-> 2777       graph_function = self._create_graph_function(args, kwargs)
   2778       self._function_cache.primary[cache_key] = graph_function
   2779       return graph_function, args, kwargs

/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes)
   2665             arg_names=arg_names,
   2666             override_flat_arg_shapes=override_flat_arg_shapes,
-> 2667             capture_by_value=self._capture_by_value),
   2668         self._function_attributes,
   2669         # Tell the ConcreteFunction to clean up its graph once it goes out of

/opt/conda/lib/python3.7/site-packages/tensorflow/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)
    979         _, original_func = tf_decorator.unwrap(python_func)
    980 
--> 981       func_outputs = python_func(*func_args, **func_kwargs)
    982 
    983       # invariant: `func_outputs` contains only Tensors, CompositeTensors,

/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in wrapped_fn(*args, **kwds)
    439         # __wrapped__ allows AutoGraph to swap in a converted function. We give
    440         # the function a weak reference to itself to avoid a reference cycle.
--> 441         return weak_wrapped_fn().__wrapped__(*args, **kwds)
    442     weak_wrapped_fn = weakref.ref(wrapped_fn)
    443 

/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs)
    966           except Exception as e:  # pylint:disable=broad-except
    967             if hasattr(e, "ag_error_metadata"):
--> 968               raise e.ag_error_metadata.to_exception(e)
    969             else:
    970               raise

ValueError: in user code:

    /opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py:571 train_function  *
        outputs = self.distribute_strategy.run(
    /opt/conda/lib/python3.7/site-packages/tensorflow_hub/keras_layer.py:222 call  *
        result = f()
    /opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/function.py:1605 __call__  **
        return self._call_impl(args, kwargs)
    /opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/function.py:1645 _call_impl
        return self._call_flat(args, self.captured_inputs, cancellation_manager)
    /opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/function.py:1730 _call_flat
        arg.shape))

    ValueError: The argument 'images' (value Tensor("IteratorGetNext:0", shape=(None, 28), dtype=float32, device=/job:worker/replica:0/task:0/device:CPU:0)) is not compatible with the shape this function was traced with. Expected shape (None, 321, 321, 3), but got shape (None, 28).
    
    If you called get_concrete_function, you may need to pass a tf.TensorSpec(..., shape=...) with a less specific shape, having None on axes which can vary.
ValueError回溯(最近一次调用)
在里面
11 m.compile(损失='binary_crossentropy',
12优化器='adam',度量=['accurity','binary_accurity'])
--->13历史记录=m.fit(ds_序列,验证数据=ds_有效,历元数=12,每个历元的步骤数=13)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in_method_包装(self,*args,**kwargs)
64定义方法包装(self,*args,**kwargs):
65如果不是自己,则为多工作模式():#pylint:disable=受保护访问
--->66返回方法(self、*args、**kwargs)
67
68#已经在"运行分配协调器"内部运行。
/opt/conda/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py in fit(self、x、y、批大小、历元、冗余、回调、验证拆分、验证数据、无序、类权重、样本权重、初始历元、每个历元的步数、验证步骤、验证批量大小、验证频率、最大队列大小、工作人员、使用多处理)
846批次大小=批次大小):
847回拨。列车上批次开始(步骤)
-->848 tmp_日志=训练函数(迭代器)
849#捕获未知大小数据集的范围错误。
850#这会一直阻塞,直到批处理完成执行。
/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in___调用(self,*args,**kwds)
578 xla_context.Exit()
579其他:
-->580结果=自调用(*args,**kwds)
581
582如果跟踪计数==self.\u获取跟踪计数():
/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in_调用(self,*args,**kwds)
625#这是u call u的第一个调用,因此我们必须初始化。
626初始值设定项=[]
-->627自我初始化(参数、KWD、添加初始化器到=初始化器)
628最后:
629#此时我们知道初始化已完成(或更少)
/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in_initialize(self、args、kwds、add_initializers_to)
504自身.\u具体的\u有状态的\u fn=(
505 self._stateful_fn._get_concrete_function_internal_garbage_collected(#pylint:disable=受保护的访问
-->506*args,**科威特第纳尔)
507
508 def无效的创建者范围(*未使用的参数,**未使用的参数):
/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/function.py in\u get\u concrete\u function\u internal\u garbage\u collected(self,*args,**kwargs)
2444 args,kwargs=None,None
2445带自锁:
->2446图形函数,u,u=self._可能定义函数(args,kwargs)
2447返回图函数
2448
/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/function.py in_-maybe_-define_函数(self、args、kwargs)
2775
2776 self.\u function\u cache.missed.add(调用上下文键)
->2777图形函数=自身。创建图形函数(args、kwargs)
2778 self.\u function\u cache.primary[cache\u key]=图形函数
2779返回图_函数,args,kwargs
/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/function.py in_create_graph_function(self、args、kwargs、override_flat_arg_shapes)
2665 arg_name=arg_name,
2666覆盖平面形状=覆盖平面形状,
->2667按值捕获=自身。_按值捕获),
2668自我功能属性,
2669#告诉concrete函数在退出时清理其图形
/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/func\u graph.py in func\u graph\u from\u py func(名称、python\u func、args、kwargs、签名、func\u图、autograph、autograph\u选项、添加控制依赖项、arg\u名称、op\u返回值、集合、按值捕获、覆盖平面arg\u形状)
979,original\u func=tf\u decorator.unwrap(python\u func)
980
-->981 func_outputs=python_func(*func_args,**func_kwargs)
982
983#不变量:`func_outputs`只包含张量、复合传感器、,
/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py in wrapped_fn(*args,**kwds)
439#uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu。我们给予
440#函数对自身进行弱引用以避免引用循环。
-->441返回弱_-wrapped_-fn()
442弱包裹的=weakref.ref(包裹的)
443
/包装器中的opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/func_graph.py(*args,**kwargs)
966例外情况为e:#pylint:disable=broad Exception
967如果hasattr(e,“ag\u错误\u元数据”):
-->968将e.ag\u错误\u元数据引发到\u异常(e)
969其他:
970加薪
ValueError:在用户代码中:
/opt/conda/lib/python3.7/site packages/tensorflow/python/keras/engine/training.py:571 train_函数*
输出=self.distribution\u strategy.run(
/opt/conda/lib/python3.7/site packages/tensorflow\u hub/keras\u layer.py:222调用*
结果=f()
/opt/conda/lib/python3.7/site-packages/tensorflow/python/eager/function.py:1605\u调用**
返回self.\u调用\u impl(args,kwargs)
/opt/conda/lib/python3.7/site packages/tensorflow/python/eager/function.py:1645\u call\u impl
返回self.\u呼叫平面(args、self.captured\u输入、取消