我正在 Google Collab 上的 MobileNetv2 预训练模型上构建迁移学习模型。直到昨天,一切都很好。但是,今天,在执行
#Create the base model(feature_extractor) from the pre-trained model MobileNet V2
_URL = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/2"
feature_extractor = hub.KerasLayer(_URL, input_shape=(_TARGET_SIZE, _TARGET_SIZE,3))
Run Code Online (Sandbox Code Playgroud)
我收到错误:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-29-663d4cbb70df> in <module>()
2 _TARGET_SIZE = 224
3 _URL = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/2"
----> 4 feature_extractor = hub.KerasLayer(_URL, input_shape=(_TARGET_SIZE, _TARGET_SIZE,3))
5 #print(feature_extractor._layers)
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/resource_variable_ops.py in _variable_handle_from_shape_and_dtype(shape, dtype, shared_name, name, graph_mode, initial_value)
165 handle_data = cpp_shape_inference_pb2.CppShapeInferenceResult.HandleData()
166 handle_data.is_set = True
--> 167 handle_data.shape_and_type.append(
168 cpp_shape_inference_pb2.CppShapeInferenceResult.HandleShapeAndType(
169 shape=shape.as_proto(), dtype=dtype.as_datatype_enum))
AttributeError: 'google.protobuf.pyext._message.RepeatedCompositeCo' object has …Run Code Online (Sandbox Code Playgroud) 我想测试从此处下载的预训练模型来执行 OCR 任务。下载链接,其名称为 CRNN_VGG_BiLSTM_CTC.onnx。该模型是从此处提取的。Sample-image.png 可以从这里下载(参见下面的代码)。
当我在 blob 中进行神经网络的前向预测 (ocr) 时,出现以下错误:
错误:OpenCV(4.4.0) /tmp/pip-req-build-xgme2194/opencv/modules/dnn/src/layers/convolution_layer.cpp:348:错误:(-215:断言失败)ngroups > 0 && inpCn %函数“getMemoryShapes”中的 ngroups == 0 && outCn % ngroups == 0
请随意阅读下面的代码。我尝试了很多东西,这很奇怪,因为这个模型不需要预定的输入形状。如果你知道如何阅读这个模型并进行转发,它也会很有帮助,但我宁愿使用 OpenCV 来解决。
import cv2 as cv
# The model is downloaded from here https://drive.google.com/drive/folders/1cTbQ3nuZG-EKWak6emD_s8_hHXWz7lAr
# model path
modelRecognition = os.path.join(MODELS_PATH,'CRNN_VGG_BiLSTM_CTC.onnx')
# read net
recognizer = cv.dnn.readNetFromONNX(modelRecognition)
# Download sample_image.png from https://i.ibb.co/fMmCB7J/sample-image.png (image host website)
sample_image = cv.imread('sample-image.png')
# Height , Width and number of channels of the …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 onnx 模型中提取输入层、输出层及其形状等数据。我知道有 python 接口可以做到这一点。我想做一些与此代码类似的事情,但是用 C++ 编写。我还粘贴了链接中的代码。我已经在 python 中尝试过了,它对我有用。我想知道是否有 C++ API 可以做同样的事情。
import onnx
model = onnx.load(r"model.onnx")
# The model is represented as a protobuf structure and it can be accessed
# using the standard python-for-protobuf methods
# iterate through inputs of the graph
for input in model.graph.input:
print (input.name, end=": ")
# get type of input tensor
tensor_type = input.type.tensor_type
# check if it has a shape:
if (tensor_type.HasField("shape")):
# iterate through dimensions of the shape:
for …Run Code Online (Sandbox Code Playgroud)