最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

tensorflow.js - TypeError: prediction.argMax is not a function - Stack Overflow

programmeradmin2浏览0评论

Using tensor flow.js for deploy model...

Model get [1,63]

I can't fix problem "const predictedClass = prediction.argMax(1).dataSync();"

async function predictGesture(coordinates) {
if (!customModel) {
    console.error("Loaded...");
    return;
}

// Проверка длины массива координат
if (coordinates.length !== 63) { // 21 точки * 3 координаты (x, y, z)
    console.error("Wrong length:", coordinates.length);
    return;
}

// Преобразование координат в тензор
const inputTensor = tf.tensor([coordinates], [1, 63]); // Создаем тензор с формой [1, 63]

let prediction; // Объявляем переменную prediction здесь, чтобы она была доступна в finally

try {
    // Выполнение предсказания
    prediction = customModel.predict(inputTensor);

    // Логируем вывод модели для отладки
    console.log("Результат предсказания:", prediction);

    // Если prediction — это не тензор, преобразуем его
    if (!(prediction instanceof tf.Tensor)) {
        if (Array.isArray(prediction)) {
            prediction = tf.tensor(prediction);
        } else {
            console.error("Ошибка: prediction не является тензором или массивом.", prediction);
            return;
        }
    }

    // Получаем индекс предсказанного класса
    const predictedClass = prediction.argMax(1).dataSync();
    console.log("Предсказанный жест:", predictedClass[0]);
} catch (error) {
    console.error("Ошибка при предсказании:", error);
} finally {
    // Очистка памяти
    inputTensor.dispose();
    if (prediction && prediction.dispose) {
        prediction.dispose();
    }
}

}

result: TypeError: prediction.argMax is not a function

发布评论

评论列表(0)

  1. 暂无评论