Я столкнулся с проблемой во время построения модели глубокого обучения и процесса обучения, когда работал с Jupyter Notebook в коде VS.
Я пытался обучить модель глубокого обучения, которую я построил с помощью Tensorflow, используя метод model.fit, но возникла проблема. Шаг 1. Генерация данных
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding, Flatten, Dense
#Define the model
model = Sequential([
Embedding(input_dim = max_words, output_dim = 64),
Flatten(),
Dense(64, activation='relu'),
Dense(4, activation='softmax') #4 categories
])
#Compile the model
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
#Train the model
history = model.fit(X_train_text, y_train,
epochs=10,
batch_size=32,
validation_data=(X_test_text, y_test))
Я столкнулся с проблемой во время построения модели глубокого обучения и процесса обучения, когда работал с Jupyter Notebook в коде VS. Я пытался обучить модель глубокого обучения, которую я построил с помощью Tensorflow, используя метод model.fit, но возникла проблема. [b]Шаг 1. Генерация данных[/b] [code]import pandas as pd import numpy as np
#Generate dummy data np.random.seed(0) n_products = 1000
#Generate random products data = { 'name': [f'Product[i]' for i in range(n_products)], 'description': [' '.join(np.random.choice(['good', 'awesome', 'excellent', 'fantastic'], size=10)) for _ in range(n_products)], 'price': np.random.randint(10, 1000, size=n_products), 'category': np.random.choice(categories, size=n_products) }
#Create DataFrame df = pd.DataFrame(data) print(df) [/code] [b]Шаг 2. Предварительная обработка данных[/b] [code]from sklearn.model_selection import train_test_split from sklearn.preprocessing import LabelEncoder from tensorflow.keras.preprocessing.text import Tokenizer from tensorflow.keras.preprocessing.sequence import pad_sequences
#Tokenize text attributes max_words = 1000 max_len = 100
#Split data into train and test sets X_train_text, X_test_text, X_train_cat, X_test_cat, y_train, y_test = train_test_split(X_text, df['category_encoded'], df['price'], test_size = 0.2, random_state=42) print("Done") print(len(X_train_text)) print(y_train) [/code] [b]Шаг 3. Построение и обучение модели с использованием Tensorflow[/b] [code]from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Embedding, Flatten, Dense
#Define the model model = Sequential([ Embedding(input_dim = max_words, output_dim = 64), Flatten(), Dense(64, activation='relu'), Dense(4, activation='softmax') #4 categories ])
#Compile the model model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
#Train the model history = model.fit(X_train_text, y_train, epochs=10, batch_size=32, validation_data=(X_test_text, y_test))
[/code] На шаге 3 я получил ошибку, как показано ниже: [code]Epoch 1/10 --------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) Cell In[13], line 18
13 model.compile(optimizer='adam', 14 loss='sparse_categorical_crossentropy', 15 metrics=['accuracy']) 17 #Train the model ---> 18 history = model.fit(X_train_text, y_train, 19 epochs=10, 20 batch_size=32, 21 validation_data=(X_test_text, y_test))
File c:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\utils\traceback_utils.py:122, in filter_traceback..error_handler(*args, **kwargs)
119 filtered_tb = _process_traceback_frames(e.__traceback__) 120 # To get the full stack trace, call: 121 # `keras.config.disable_traceback_filtering()` --> 122 raise e.with_traceback(filtered_tb) from None 123 finally: 124 del filtered_tb
File c:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\tensorflow\python\eager\execute.py:53, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
File "c:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\backend\tensorflow\nn.py", line 638, in sparse_categorical_crossentropy
Received a label value of 981 which is outside the valid range of [0, 4). Label values: 799 555 895 885 300 152 513 436 397 525 907 616 981 939 147 724 851 857 465 953 710 764 630 521 77 234 744 169 963 916 472 237 [[{{node compile_loss/sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits}}]] [Op:__inference_one_step_on_iterator_3817] Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings... [/code] Я думал, что возникла проблема с предварительной обработкой данных, но понятия не имею, как ее решить.
I’m currently engaged in a project where I utilize a deep learning model to generate segmentation masks. However, I’ve encountered a persistent challenge with the jagged edges on the masks outputted by my model. This issue becomes particularly...
Я обращаюсь к вам, так как не смог найти решение своей проблемы, мне удалось построить модель DL и сохранить ее в формате h5 (70 МБ), которую я сохранил на GitHub , и я попытался развернуть его в потоке, используя код Python, который вызывает модель...
Я обращаюсь к вам, так как не смог найти решение своей проблемы, мне удалось построить модель DL и сохранить ее в формате h5 (70 МБ), которую я сохранил на GitHub , и я попытался развернуть его в потоке, используя код Python, который вызывает модель...
Я обращаюсь к вам, так как не смог найти решение своей проблемы, мне удалось построить модель DL и сохранить ее в формате h5 (70 МБ), которую я сохранил на GitHub , и я попытался развернуть его в потоке, используя код Python, который вызывает модель...
Я работаю с различными квантованными реализациями одной и той же модели, основное различие заключается в точности весов, смещений и активаций. Поэтому я хотел бы знать, как мне найти разницу между размером модели в МБ, например, с 32-битной...