You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TensorFlow+AMD GPU语音识别项目遇0xC0000005错误求助

TensorFlow-DirectML测试阶段触发0xC0000005错误求助

我使用Python的TensorFlow开发语音识别项目,由于TensorFlow原生仅支持CPU或NVIDIA GPU,为AMD Radeon 7600S GPU安装了微软开发的tensorflow-directml-plugin,已成功让TensorFlow识别到GPU。但运行代码时,数据集下载、模型训练均正常,在测试阶段却出现错误:Process finished with exit code -1073741819 (0xC0000005)。

已尝试以下操作,均未解决问题:

  • 重启电脑
  • 以管理员权限运行代码
  • 尝试强制使用CPU(但代码仍会调用GPU)

其他TensorFlow项目可正常运行,以下是当前项目代码:

import os
import tensorflow as tf
import tensorflow_datasets as tfds
import numpy as np


(ds_train_full,), ds_info = tfds.load(
    'spoken_digit',
    split=['train'],
    as_supervised=True,
    with_info=True
)

commands = ds_info.features['label'].names
num_classes = len(commands)
print("Tanınacak komutlar:", commands)


dataset_size = ds_info.splits['train'].num_examples
train_size = int(0.8 * dataset_size)

ds_train = ds_train_full.take(train_size)
ds_test = ds_train_full.skip(train_size)



def preprocess_audio(audio, label):
    audio = tf.cast(audio, tf.float32)


    audio = audio[:16000]
    zero_padding = tf.zeros([16000 - tf.shape(audio)[0]], dtype=tf.float32)
    audio = tf.concat([audio, zero_padding], 0)

    spectrogram = tf.signal.stft(audio, frame_length=255, frame_step=128)
    spectrogram = tf.abs(spectrogram)
    spectrogram = tf.expand_dims(spectrogram, -1)

    return spectrogram, label


AUTOTUNE = tf.data.AUTOTUNE
batch_size = 32

ds_train = ds_train.map(preprocess_audio, num_parallel_calls=AUTOTUNE)
ds_train = ds_train.batch(batch_size).cache().prefetch(AUTOTUNE)

ds_test = ds_test.map(preprocess_audio, num_parallel_calls=AUTOTUNE)
ds_test = ds_test.batch(batch_size).cache().prefetch(AUTOTUNE)


model = tf.keras.Sequential([
    tf.keras.layers.Input(shape=(124, 129, 1)),  # STFT sonrası approx. shape
    tf.keras.layers.Conv2D(32, (3, 3), activation='relu'),
    tf.keras.layers.Conv2D(64, (3, 3), activation='relu'),
    tf.keras.layers.MaxPooling2D((2, 2)),
    tf.keras.layers.Dropout(0.25),
    tf.keras.layers.GlobalAveragePooling2D(),
    tf.keras.layers.Dense(128, activation='relu'),
    tf.keras.layers.Dropout(0.5),
    tf.keras.layers.Dense(num_classes, activation='softmax')
])

model.compile(
    optimizer='adam',
    loss='sparse_categorical_crossentropy',
    metrics=['accuracy']
)

model.summary()


epochs = 5
model.fit(ds_train, validation_data=ds_test, epochs=epochs)


model.save("spoken_digit_model.keras")
print("Model kaydedildi: spoken_digit_model.keras")



def predict_wav(model, wav_file_path, commands):
    audio_binary = tf.io.read_file(wav_file_path)
    audio, _ = tf.audio.decode_wav(audio_binary)
    audio = tf.squeeze(audio, axis=-1)


    if tf.shape(audio)[0] > 16000:
        audio = audio[:16000]
    elif tf.shape(audio)[0] < 16000:
        padding = tf.zeros([16000 - tf.shape(audio)[0]], dtype=tf.float32)
        audio = tf.concat([audio, padding], 0)

    spectrogram = tf.signal.stft(audio, frame_length=255, frame_step=128)
    spectrogram = tf.abs(spectrogram)
    spectrogram = spectrogram[tf.newaxis, ..., tf.newaxis]

    prediction = model.predict(spectrogram)
    predicted_id = np.argmax(prediction[0])
    return commands[predicted_id], prediction[0][predicted_id]



wav_file = "Kayit.wav"
predicted_command, confidence = predict_wav(model, wav_file, commands)
print(f"Tahmin: {predicted_command}, Güven: {confidence:.4f}")

希望能得到解决该错误的帮助,感谢支持。

内容的提问来源于stack exchange,提问作者Ömer Faruk Solmaz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 11:45:09