我正在尝试将onnx模型转换为tflite,我面临执行行错误tf_rep.export_graph(tf_model_path)。这个问题之前在 SO 中被问过,但没有提供明确的解决方案。
安装要求:tensorflow: 2.12.0, onnx 1.14.0, onnx-tf 1.10.0,Python 3.10.12
import torch
import onnx
import tensorflow as tf
import onnx_tf
from torchvision.models import resnet50
# Load the PyTorch ResNet50 model
pytorch_model = resnet50(pretrained=True)
pytorch_model.eval()
# Export the PyTorch model to ONNX format
input_shape = (1, 3, 224, 224)
dummy_input = torch.randn(input_shape)
onnx_model_path = 'resnet50.onnx'
torch.onnx.export(pytorch_model, dummy_input, onnx_model_path, opset_version=12, verbose=False)
# Load the ONNX model
onnx_model = onnx.load(onnx_model_path)
# Convert …Run Code Online (Sandbox Code Playgroud) 这是一个非常愚蠢的问题。语法规则afaik中没有错误,但没有给出正确的输出。我一直在盯着它,但我看不到错误。
我可以使用哪些工具来帮助我了解解析中发生了什么?我尝试插入跟踪代码的工作量很大,似乎并没有太大帮助。
解析器
%{
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include "SymbolTable.h"
#include "SymbolInfo.h"
#include "ScopeTable.h"
int yyparse(void);
int yylex(void);
extern char* yytext;
extern FILE * yyin;
extern int tableSize;
FILE *logout;
extern int line_count;
extern char *arr[100];
extern char *final_arr[100];
SymbolTable *table;
void yyerror (const char *s)
{
fprintf(stderr,"%s\n",s);
return;
}
%}
%union {
class SymbolInfo* sym;
char *s;
float f;
}
%error-verbose
%verbose
%token COMMA INT ID SEMICOLON FLOAT VOID LCURL RCURL RETURN NOT IF FOR WHILE PRINTLN LPAREN RPAREN
%token …Run Code Online (Sandbox Code Playgroud) 我有一个使用我的数据集派生的训练集y_train(有 8 个独特的类)train_test_split。
y_train
2019 AD
777 QUERY
282 INFO
1879 REAL
910 QUERY
...
997 QUERY
510 FAKE
252 REAL
1334 FAKE
1579 INFO
Name: target, Length: 1653, dtype: object
Run Code Online (Sandbox Code Playgroud)
现在,当我to_categorical在这组上运行时,我收到此错误。
y_train = to_categorical(np.asarray(y_train),8, dtype='O')
41 """
42
---> 43 y = np.array(y, dtype='int')
44 input_shape = y.shape
45 if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:
ValueError: invalid literal for int() with base 10: 'AD'
Run Code Online (Sandbox Code Playgroud)
我也尝试过, y_train = to_categorical(np.asarray(y_train))但它给出了同样的错误,我不明白为什么?dtype …