Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Input 0 of layer conformer_encoder_subsampling_1 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 8000, 1) #14393

Closed
TEJASK111 opened this issue Jan 22, 2021 · 3 comments
Assignees
Labels
stale stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@TEJASK111
Copy link

I am trying to use the code to predict text from speech but I get error in it .
Code :
import os
import argparse
from tensorflow_asr.utils import setup_environment, setup_devices
import librosa
setup_environment()
import tensorflow as tf
import IPython.display as ipd

DEFAULT_YAML = os.path.join(os.path.abspath(os.path.dirname(file)), "config.yml")

tf.keras.backend.clear_session()

parser = argparse.ArgumentParser(prog="Conformer Testing")

parser.add_argument("--config", type=str, default=DEFAULT_YAML,
help="The file path of model configuration file")

parser.add_argument("--saved", type=str, default=None,
help="Path to saved model")

parser.add_argument("--mxp", default=False, action="store_true",
help="Enable mixed precision")

parser.add_argument("--device", type=int, default=0,
help="Device's id to run test on")

parser.add_argument("--cpu", default=False, action="store_true",
help="Whether to only use cpu")

args = parser.parse_args()

tf.config.optimizer.set_experimental_options({"auto_mixed_precision": args.mxp})

setup_devices([args.device], cpu=args.cpu)

from tensorflow_asr.configs.config import Config
from tensorflow_asr.featurizers.speech_featurizers import TFSpeechFeaturizer
from tensorflow_asr.models.conformer import ConformerEncoder

config = Config(args.config, learning=True)
speech_featurizer = TFSpeechFeaturizer(config.speech_config)

assert args.saved

build model

model = ConformerEncoder(**config.model_config)
model(tf.keras.Input(shape=speech_featurizer.shape, dtype=tf.float32), training=False)
model.load_weights(args.saved, by_name=True)
model.summary(line_length=120)
#conformer.encoder.save_weights("./conformer-encoder.h5")

def predict(audio,shape_num=8000):
prob=model.predict(audio.reshape(1,shape_num,1))
index=np.argmax(prob[0])
return classes[index]

import sounddevice as sd
import soundfile as sf

samplerate = 16000
duration = 1 # seconds
filename = 'output.wav'
print("start")
mydata = sd.rec(int(samplerate * duration), samplerate=samplerate,
channels=1, blocking=True)
print("end")
sd.wait()
sf.write(filename, mydata, samplerate)
os.listdir('D:/New folder (16)/New folder/')
filepath='D:/New folder (16)/New folder'
#reading the voice commands
samples, sample_rate = librosa.load(filepath + '/' + 'output.wav', sr = 16000)
samples = librosa.resample(samples, sample_rate, 8000)
ipd.Audio(samples,rate=8000)
predict(samples)

Error :
ValueError: Input 0 of layer conformer_encoder_subsampling_1 is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (None, 8000, 1)
Plzzz help me with this.

@saikumarchalla saikumarchalla added the type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited. label Feb 4, 2021
@chunduriv chunduriv self-assigned this Nov 8, 2021
@chunduriv
Copy link
Collaborator

@TEJASK111, Sorry for the late response. Is this still an issue for you?

The input layers of the model needs a 4 dimension tensor to work with but the input tensor you are passing to it has only 3 dimensions. To fix this issue, you need to reshape the input tensor to a 4 dimension before training your model.

@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.

@google-ml-butler
Copy link

Closing as stale. Please reopen if you'd like to work on this further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.
Projects
None yet
Development

No branches or pull requests

4 participants