airockchip / rknn-toolkit2

Other
760 stars 78 forks source link

No Op registered for TensorListReserve with domain_version of 18 #121

Open lk07828 opened 4 weeks ago

lk07828 commented 4 weeks ago

使用tensorflow+LSTM训练了一个模型并保存为了tflite格式。使用 rknn-toolkit2_2.0.0b23+29ceb58d 转换rknn时遇到了如下报错: image

构建模型的代码如下:

# LSTM模型建立
    # 0-1标准化
    print('1.数据归一化')
    scaler = MinMaxScaler()
    data_for_training = scaler.fit_transform(df)

    # 文件夹路径
    folder_path = './files/'
    # 检查文件夹是否存在,如果不存在则创建
    if not os.path.exists(folder_path):
        os.makedirs(folder_path)
    file_path = os.path.join(folder_path, f'scaler_{item_code}_{type}.pkl')
    with open(file_path, 'wb') as file:
        pickle.dump(scaler, file)

    print(file_path)

    def dataset(data, win_size):
        X, y = [], []
        for i in range(win_size, len(data)):
            X.append(data[i - win_size:i])
            y.append(data[i, 0])

        X, Y = np.array(X), np.array(y)
        X = X.reshape((X.shape[0], win_size, feature_count))

        return X, Y

    data_x, data_y = dataset(data_for_training, win_size)

    train_x, test_x, train_y, test_y = train_test_split(data_x, data_y, test_size=0.2, shuffle=False)

    print('2、建模')
    my_model = Sequential()
    my_model.add(LSTM(neurons[0], return_sequences=True, input_shape=(train_x.shape[1], train_x.shape[2])))
    for n in range(1, hidden_layers):
        if n < hidden_layers - 1:
            my_model.add(LSTM(neurons[n], return_sequences=True))
        else:
            my_model.add(LSTM(neurons[n]))

    my_model.add(Dropout(0.1))
    my_model.add(Dense(1))
    my_model.summary()
    print('3、配置训练方法')
    # 损失函数(loss)为均方误差(Mean Squared Error),适用于回归问题
    # 优化器(optimizer)为 Adam,是一种常用的优化算法
    my_model.compile(loss='mae', optimizer='adam')
    print('4、训练模型')
    my_model.fit(train_x, train_y, batch_size=batch_size, epochs=epochs, verbose=0, validation_split=0.2, shuffle=False)
    print('5、保存模型')
    my_model.save('files/model_' + item_code + '_hour.pkl')

    # # 转换为TensorFlow Lite模型
    converter = tf.lite.TFLiteConverter.from_keras_model(my_model)
    converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS, tf.lite.OpsSet.SELECT_TF_OPS]
    converter._experimental_lower_tensor_list_ops = False
    tflite_model = converter.convert()
yuyun2000 commented 4 weeks ago

1、使用2.1的工具,但是大概率还是不行 2、tflite转为onnx模型再次转换 3、使用pytroch构建这个模型,转为onnx再转rknn

lk07828 commented 4 weeks ago

试过2.1 了,报错是一样的。我再继续试试其他2种方法