[Python] Error: 'Could not find variable batch_normalization_7/beta' when deploying custom...

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I have trained my model using transfer learning and model sequential.

    inceptionv3_model = InceptionV3(weights="imagenet", include_top=False, input_shape=(224, 224, 3))
    inceptionv3_model.trainable = False

    model = Sequential()
    model.add(inceptionv3_model)

    model.add(Conv2D(32, (3, 3), activation='relu', padding='same'))
    model.add(GlobalAveragePooling2D())

    # flatten
    model.add(Flatten())

    # hidden layer
    model.add(Dense(64, activation='relu'))
    model.add(Dropout(0.2))

    # output layer
    model.add(Dense(3, activation='softmax'))


    After finish the fitting model, save the model using SavedModel format.

    saved_model_path = '/kaggle/working/models/cdb_model/1'
    tf.saved_model.save(model, saved_model_path)


    and the i want to deploy using TF-Serving on docker. Create docker image tf-serving and create docker container to running.

    docker pull tf/serving

    docker run -it -v models:/models -p 8501:8501 --entrypoint /bin/ba
    sh tensorflow/serving

    tensorflow_model_server --rest_api_port=8501 --model_name=cdb_model --model_base_path=
    /models/cdb_model/


    If i check endpoint url, status ok.

    [​IMG]

    but when POST image for prediction

    def images_preprocessing(filename):
    img = image.load_img(filename, target_size=(224, 224))
    img_array = image.img_to_array(img)
    img_array = np.expand_dims(img_array, axis=0)
    img_array = img_array / 255.0
    return img_array
    image = images_preprocessing(cat_path)
    json_data = {
    "instances": image.tolist()
    }
    endpoint = "http://localhost:8501/v1/models/cdb_model:predict"
    response = requests.post(endpoint, json=json_data)
    predictions = response.json()
    print(predictions)


    json return error:

    {'error': 'Could not find variable batch_normalization_7/beta. This could mean that the variable has been deleted. In TF1, it can also mean the variable is uninitialized. Debug info: container=localhost, status error message=Resource localhost/batch_normalization_7/beta/N10tensorflow3VarE does not exist.\n\t [[{{function_node __inference_serving_default_199623}}{{node sequential_1/inception_v3_1/batch_normalization_7_1/Cast_2/ReadVariableOp}}]]'}

    Continue reading...

Compartilhe esta Página