1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] AttributeError: 'Dense' object has no attribute 'output_shape' in ann_visualizer with...

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    `i have this error for Epoch 1/2 1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 391ms/step - loss: 6272135168.0000 Epoch 2/2 1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 16ms/step - loss: 6272133632.0000 1/1 ━━━━━━━━━━━━━━━━━━━━ 0s 16ms/step Mean Squared Error: 7431671762.639743 Traceback (most recent call last):

    File ~\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec exec(code, globals, locals)

    File c:\users\mouli.spyder-py3\temp.py:27 ann_viz(model,title='Linear Regression')

    File ~\anaconda3\Lib\site-packages\ann_visualizer\visualize.py:42 in ann_viz input_layer = int(str(layer.input_shape).split(",")[1][1:-1]);

    AttributeError: 'Dense' object has no attribute 'input_shape'

    for this

    `

    import numpy as np
    import tensorflow as tf
    from tensorflow import keras
    from sklearn.model_selection import train_test_split
    from sklearn.metrics import mean_squared_error
    import matplotlib.pyplot as plt
    import pandas as pd`
    `# Importing the dataset
    dataset = pd.read_csv(r"Salary_Data (1).csv")
    X = dataset.iloc[:, :-1].values
    y = dataset.iloc[:, 1].values
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
    model = keras.Sequential([
    keras.layers.Input(shape=(1,)),
    keras.layers.Dense`(1)
    ])`
    model.compile(optimizer='adam', loss='mean_squared_error')
    model.fit(`your text`X_train, y_train, epochs=2, batch_size=32, verbose=1)
    y_pred = model.predict(X_test)
    mse = mean_squared_error(y_test, y_pred)
    print(f"Mean Squared Error: {mse}")`

    # Visualize the data and the regression line

    #Visualizing the neural network
    from ann_visualizer.visualize import ann_viz
    from graphviz `your text`import Source
    ann_viz(model,title='Linear Regression')
    graph_source=Source.from_file('network.gv')

    Continue reading...

Compartilhe esta Página