keras报错:ValueError: `steps_per_epoch=None` is only valid for a generator based on the `keras.utils.S

keras报错:

ValueError: `steps_per_epoch=None` is only valid for a generator based on the `keras.utils.Sequence` class. Please specify `steps_per_epoch` or use the `keras.utils.Sequence` class.

解决方法:

在fit_generator中添加参数:

steps_per_epoch=x_train.shape[0],

 

import tensorflow as tf import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.preprocessing import MinMaxScaler import os # 1. 数据预处理 (保持不变) def load_and_preprocess_data(csv_path): """加载并预处理双色球历史数据""" df = pd.read_csv(csv_path) red_balls = df.iloc[:, 0:6].values.astype(np.float32) blue_balls = df.iloc[:, 6:].values.reshape(-1, 1).astype(np.float32) red_scaler = MinMaxScaler(feature_range=(0, 1)).fit(red_balls) blue_scaler = MinMaxScaler(feature_range=(0, 1)).fit(blue_balls) red_normalized = red_scaler.transform(red_balls) blue_normalized = blue_scaler.transform(blue_balls) combined = np.hstack((red_normalized, blue_normalized)) X_train, _ = train_test_split(combined, test_size=0.2, random_state=42) return X_train, red_scaler, blue_scaler # 2. 重构GAN模型 class DualColorGAN(tf.keras.Model): def __init__(self, latent_dim=100): super(DualColorGAN, self).__init__() self.latent_dim = latent_dim # 生成器 self.generator = tf.keras.Sequential([ tf.keras.layers.Dense(256, activation='relu', input_dim=latent_dim), tf.keras.layers.BatchNormalization(), tf.keras.layers.Dense(512, activation='relu'), tf.keras.layers.BatchNormalization(), tf.keras.layers.Dense(1024, activation='relu'), tf.keras.layers.BatchNormalization(), tf.keras.layers.Dense(7, activation='sigmoid') ]) # 判别器 self.discriminator = tf.keras.Sequential([ tf.keras.layers.Dense(512, activation='relu', input_dim=7), tf.keras.layers.Dense(256, activation='relu'), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dense(1, activation='sigmoid') ]) # 分离优化器 (关键修复) self.g_optimizer = tf.keras.optimizers.Adam(0.0002, beta_1=0.5) self.d_optimizer = tf.keras.optimizers.Adam(0.0002, beta_1=0.5) self.loss_fn = tf.keras.losses.BinaryCrossentropy() def compile(self, **kwargs): super().compile(**kwargs) # 重构训练步骤 def train_step(self, real_data): batch_size = tf.shape(real_data)[0] # 训练判别器 with tf.GradientTape() as d_tape: noise = tf.random.normal([batch_size, self.latent_dim]) generated_data = self.generator(noise, training=False) real_output = self.discriminator(real_data, training=True) fake_output = self.discriminator(generated_data, training=True) # 损失计算 real_loss = self.loss_fn(tf.ones_like(real_output), real_output) fake_loss = self.loss_fn(tf.zeros_like(fake_output), fake_output) d_loss = (real_loss + fake_loss) / 2 # 仅更新判别器变量 d_grads = d_tape.gradient(d_loss, self.discriminator.trainable_variables) self.d_optimizer.apply_gradients(zip(d_grads, self.discriminator.trainable_variables)) # 训练生成器 with tf.GradientTape() as g_tape: noise = tf.random.normal([batch_size, self.latent_dim]) generated_data = self.generator(noise, training=True) fake_output = self.discriminator(generated_data, training=True) g_loss = self.loss_fn(tf.ones_like(fake_output), fake_output) # 仅更新生成器变量 g_grads = g_tape.gradient(g_loss, self.generator.trainable_variables) self.g_optimizer.apply_gradients(zip(g_grads, self.generator.trainable_variables)) return {"d_loss": d_loss, "g_loss": g_loss} # 3. 训练与预测 def train_and_predict(csv_path, epochs=5000, batch_size=32): X_train, red_scaler, blue_scaler = load_and_preprocess_data(csv_path) dataset = tf.data.Dataset.from_tensor_slices(X_train).shuffle(1000).batch(batch_size) gan = DualColorGAN(latent_dim=100) gan.compile() # 训练前构建模型 (避免变量延迟创建) dummy_input = tf.random.normal([1, 100]) _ = gan.generator(dummy_input) _ = gan.discriminator(dummy_input) for epoch in range(epochs): for batch in dataset: metrics = gan.train_step(batch) if epoch % 500 == 0: print(f"Epoch {epoch}, D Loss: {metrics['d_loss']:.4f}, G Loss: {metrics['g_loss']:.4f}") # 生成预测号码 (保持不变) def generate_numbers(n=5): noise = tf.random.normal(shape=(n, 100)) generated = gan.generator(noise).numpy() red_generated = generated[:, :6] blue_generated = generated[:, 6:] red_denorm = red_scaler.inverse_transform(red_generated) blue_denorm = blue_scaler.inverse_transform(blue_generated) red_denorm = np.clip(red_denorm, 1, 33).astype(int) blue_denorm = np.clip(blue_denorm, 1, 16).astype(int) results = [] for i in range(n): unique_red = np.unique(red_denorm[i]) while len(unique_red) < 6: new_red = np.random.randint(1, 34, 6 - len(unique_red)) unique_red = np.unique(np.concatenate([unique_red, new_red])) sorted_red = np.sort(unique_red[:6]) results.append({ "红球": sorted_red.tolist(), "蓝球": int(blue_denorm[i][0]) }) return results return generate_numbers() # 4. 使用示例 if __name__ == "__main__": csv_path = "D:/worker/lottery_results7.csv" predictions = train_and_predict(csv_path, epochs=300) print("\n双色球预测号码:") for i, pred in enumerate(predictions, 1): print(f"预测组 {i}: 红球: {pred['红球']}, 蓝球: {pred['蓝球']}") C:\Users\power\AppData\Roaming\Python\Python39\site-packages\keras\src\layers\core\dense.py:87: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead. super().__init__(activity_regularizer=activity_regularizer, **kwargs) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[1], line 145 143 if __name__ == "__main__": 144 csv_path = "D:/worker/lottery_results7.csv" --> 145 predictions = train_and_predict(csv_path, epochs=300) 147 print("\n双色球预测号码:") 148 for i, pred in enumerate(predictions, 1): Cell In[1], line 103, in train_and_predict(csv_path, epochs, batch_size) 101 dummy_input = tf.random.normal([1, 100]) 102 _ = gan.generator(dummy_input) --> 103 _ = gan.discriminator(dummy_input) 105 for epoch in range(epochs): 106 for batch in dataset: File ~\AppData\Roaming\Python\Python39\site-packages\keras\src\utils\traceback_utils.py:122, in filter_traceback.<locals>.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 ~\AppData\Roaming\Python\Python39\site-packages\keras\src\layers\input_spec.py:227, in assert_input_compatibility(input_spec, inputs, layer_name) 222 for axis, value in spec.axes.items(): 223 if value is not None and shape[axis] not in { 224 value, 225 None, 226 }: --> 227 raise ValueError( 228 f'Input {input_index} of layer "{layer_name}" is ' 229 f"incompatible with the layer: expected axis {axis} " 230 f"of input shape to have value {value}, " 231 "but received input with " 232 f"shape {shape}" 233 ) 234 # Check shape. 235 if spec.shape is not None: ValueError: Exception encountered when calling Sequential.call(). Input 0 of layer "dense_4" is incompatible with the layer: expected axis -1 of input shape to have value 7, but received input with shape (1, 100) Arguments received by Sequential.call(): • inputs=tf.Tensor(shape=(1, 100), dtype=float32) • training=None • mask=None 根据ValueError的要求修改完善代码,并生成完整代码
最新发布
08-21
import tensorflow as tf import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.preprocessing import MinMaxScaler import os # 1. 数据预处理 (保持不变) def load_and_preprocess_data(csv_path): """加载并预处理双色球历史数据""" df = pd.read_csv(csv_path) red_balls = df.iloc[:, 0:6].values.astype(np.float32) blue_balls = df.iloc[:, 6:].values.reshape(-1, 1).astype(np.float32) red_scaler = MinMaxScaler(feature_range=(0, 1)).fit(red_balls) blue_scaler = MinMaxScaler(feature_range=(0, 1)).fit(blue_balls) red_normalized = red_scaler.transform(red_balls) blue_normalized = blue_scaler.transform(blue_balls) combined = np.hstack((red_normalized, blue_normalized)) X_train, _ = train_test_split(combined, test_size=0.2, random_state=42) return X_train, red_scaler, blue_scaler # 2. 重构GAN模型 class DualColorGAN(tf.keras.Model): def __init__(self, latent_dim=100): super(DualColorGAN, self).__init__() self.latent_dim = latent_dim # 生成器 self.generator = tf.keras.Sequential([ tf.keras.layers.Dense(256, activation='relu', input_dim=latent_dim), tf.keras.layers.BatchNormalization(), tf.keras.layers.Dense(512, activation='relu'), tf.keras.layers.BatchNormalization(), tf.keras.layers.Dense(1024, activation='relu'), tf.keras.layers.BatchNormalization(), tf.keras.layers.Dense(7, activation='sigmoid') ]) # 判别器 self.discriminator = tf.keras.Sequential([ tf.keras.layers.Dense(512, activation='relu', input_dim=7), tf.keras.layers.Dense(256, activation='relu'), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dense(1, activation='sigmoid') ]) # 分离优化器 (关键修复) self.g_optimizer = tf.keras.optimizers.Adam(0.0002, beta_1=0.5) self.d_optimizer = tf.keras.optimizers.Adam(0.0002, beta_1=0.5) self.loss_fn = tf.keras.losses.BinaryCrossentropy() def compile(self, **kwargs): super().compile(**kwargs) # 重构训练步骤 def train_step(self, real_data): batch_size = tf.shape(real_data)[0] # 训练判别器 with tf.GradientTape() as d_tape: noise = tf.random.normal([batch_size, self.latent_dim]) generated_data = self.generator(noise, training=False) real_output = self.discriminator(real_data, training=True) fake_output = self.discriminator(generated_data, training=True) # 损失计算 real_loss = self.loss_fn(tf.ones_like(real_output), real_output) fake_loss = self.loss_fn(tf.zeros_like(fake_output), fake_output) d_loss = (real_loss + fake_loss) / 2 # 仅更新判别器变量 d_grads = d_tape.gradient(d_loss, self.discriminator.trainable_variables) self.d_optimizer.apply_gradients(zip(d_grads, self.discriminator.trainable_variables)) # 训练生成器 with tf.GradientTape() as g_tape: noise = tf.random.normal([batch_size, self.latent_dim]) generated_data = self.generator(noise, training=True) fake_output = self.discriminator(generated_data, training=True) g_loss = self.loss_fn(tf.ones_like(fake_output), fake_output) # 仅更新生成器变量 g_grads = g_tape.gradient(g_loss, self.generator.trainable_variables) self.g_optimizer.apply_gradients(zip(g_grads, self.generator.trainable_variables)) return {"d_loss": d_loss, "g_loss": g_loss} # 3. 训练与预测 def train_and_predict(csv_path, epochs=5000, batch_size=32): X_train, red_scaler, blue_scaler = load_and_preprocess_data(csv_path) dataset = tf.data.Dataset.from_tensor_slices(X_train).shuffle(1000).batch(batch_size) gan = DualColorGAN(latent_dim=100) gan.compile() # 训练前构建模型 (避免变量延迟创建) dummy_input = tf.random.normal([1, 100]) _ = gan.generator(dummy_input) _ = gan.discriminator(dummy_input) for epoch in range(epochs): for batch in dataset: metrics = gan.train_step(batch) if epoch % 500 == 0: print(f"Epoch {epoch}, D Loss: {metrics['d_loss']:.4f}, G Loss: {metrics['g_loss']:.4f}") # 生成预测号码 (保持不变) def generate_numbers(n=5): noise = tf.random.normal(shape=(n, 100)) generated = gan.generator(noise).numpy() red_generated = generated[:, :6] blue_generated = generated[:, 6:] red_denorm = red_scaler.inverse_transform(red_generated) blue_denorm = blue_scaler.inverse_transform(blue_generated) red_denorm = np.clip(red_denorm, 1, 33).astype(int) blue_denorm = np.clip(blue_denorm, 1, 16).astype(int) results = [] for i in range(n): unique_red = np.unique(red_denorm[i]) while len(unique_red) < 6: new_red = np.random.randint(1, 34, 6 - len(unique_red)) unique_red = np.unique(np.concatenate([unique_red, new_red])) sorted_red = np.sort(unique_red[:6]) results.append({ "红球": sorted_red.tolist(), "蓝球": int(blue_denorm[i][0]) }) return results return generate_numbers() # 4. 使用示例 if __name__ == "__main__": csv_path = "D:/worker/lottery_results7.csv" predictions = train_and_predict(csv_path, epochs=300) print("\n双色球预测号码:") for i, pred in enumerate(predictions, 1): print(f"预测组 {i}: 红球: {pred['红球']}, 蓝球: {pred['蓝球']}") C:\Users\power\AppData\Roaming\Python\Python39\site-packages\keras\src\layers\core\dense.py:87: UserWarning: Do not pass an `input_shape`/`input_dim` argument to a layer. When using Sequential models, prefer using an `Input(shape)` object as the first layer in the model instead. super().__init__(activity_regularizer=activity_regularizer, **kwargs) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[1], line 145 143 if __name__ == "__main__": 144 csv_path = "D:/worker/lottery_results7.csv" --> 145 predictions = train_and_predict(csv_path, epochs=300) 147 print("\n双色球预测号码:") 148 for i, pred in enumerate(predictions, 1): Cell In[1], line 103, in train_and_predict(csv_path, epochs, batch_size) 101 dummy_input = tf.random.normal([1, 100]) 102 _ = gan.generator(dummy_input) --> 103 _ = gan.discriminator(dummy_input) 105 for epoch in range(epochs): 106 for batch in dataset: File ~\AppData\Roaming\Python\Python39\site-packages\keras\src\utils\traceback_utils.py:122, in filter_traceback.<locals>.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 ~\AppData\Roaming\Python\Python39\site-packages\keras\src\layers\input_spec.py:227, in assert_input_compatibility(input_spec, inputs, layer_name) 222 for axis, value in spec.axes.items(): 223 if value is not None and shape[axis] not in { 224 value, 225 None, 226 }: --> 227 raise ValueError( 228 f'Input {input_index} of layer "{layer_name}" is ' 229 f"incompatible with the layer: expected axis {axis} " 230 f"of input shape to have value {value}, " 231 "but received input with " 232 f"shape {shape}" 233 ) 234 # Check shape. 235 if spec.shape is not None: ValueError: Exception encountered when calling Sequential.call(). Input 0 of layer "dense_4" is incompatible with the layer: expected axis -1 of input shape to have value 7, but received input with shape (1, 100) Arguments received by Sequential.call(): • inputs=tf.Tensor(shape=(1, 100), dtype=float32) • training=None • mask=None 根据ValueError的要求修改完善代码
08-21
import tensorflow as tf import os import matplotlib.pyplot as plt from time import time # 定义标签字典(根据实际类别修改) label_dict = { 'electrodrill': 0, 'headphones': 1, 'keyboard': 2, 'mobile_phone': 3, 'monitor': 4, 'mouse': 5, 'multimeter': 6, 'number': 7, 'oscillograph': 8, 'pliers': 9, 'printer': 10, 'screwdriver': 11, 'soldering_iron': 12, 'speaker': 13, 'tape_measure': 14, 'wrench': 15 } def data_load(data_dir, test_data_dir, img_height, img_width, batch_size): def process_image(image_path): image = tf.io.read_file(image_path) image = tf.image.decode_jpeg(image, channels=3) image = tf.image.resize(image, [img_height, img_width]) image = (image / 127.5) - 1.0 # MobileNet标准化 return image def parse_path(path): # 转换为numpy字符串处理路径 path_str = path.numpy().decode('utf-8') # 获取类别文件夹名 class_name = tf.strings.split(path_str, os.path.sep)[-2].numpy().decode('utf-8') # 从预定义的字典获取标签索引 label_idx = label_dict.get(class_name, -1) # -1表示未知类别 if label_idx == -1: raise ValueError(f"未知类别: {class_name}") return process_image(path), label_idx def map_fn(path): # 使用py_function包装Python逻辑 image, label = tf.py_function( func=parse_path, inp=[path], Tout=[tf.float32, tf.int32] ) # 设置明确的Tensor形状 image.set_shape([img_height, img_width, 3]) label.set_shape([]) # 将标签转换为one-hot编码 label = tf.one_hot(label, depth=len(label_dict)) return image, label def load_dataset(directory): # 获取所有图片路径 dataset = tf.data.Dataset.list_files(directory + '/*/*.jpg', shuffle=True) # 应用处理函数 dataset = dataset.map( map_fn, num_parallel_calls=tf.data.experimental.AUTOTUNE ) return dataset # 加载数据集 train_ds = load_dataset(data_dir) val_ds = load_dataset(test_data_dir) # 批处理和预取 train_ds = train_ds.batch(batch_size).prefetch(tf.data.experimental.AUTOTUNE) val_ds = val_ds.batch(batch_size).prefetch(tf.data.experimental.AUTOTUNE) # 验证数据预处理是否正确 for images, labels in train_ds.take(1): # 检查图像标准化是否正确 min_value = tf.reduce_min(images) max_value = tf.reduce_max(images) print(f"图像标准化检查: 最小值 = {min_value.numpy()}, 最大值 = {max_value.numpy()}") assert min_value >= -1 and max_value <= 1, "图像标准化错误,范围应为[-1, 1]" # 检查标签是否为one-hot编码且正确 print("标签示例:", labels[0].numpy()) # 应为one-hot如[0,0,1,...,0] assert tf.reduce_sum(labels[0]).numpy() == 1, "标签应该是one-hot编码,其中只有一个值为1,其余为0" return train_ds, val_ds def model_load(IMG_SHAPE=(224, 224, 3), class_num=16, learning_rate=0.01): # 添加learning_rate参数 base_model = tf.keras.applications.MobileNetV2( input_shape=IMG_SHAPE, include_top=False, weights='imagenet' ) base_model.trainable = False model = tf.keras.Sequential([ base_model, tf.keras.layers.GlobalAveragePooling2D(), tf.keras.layers.Dense(class_num, activation='softmax') ]) # 显式设置学习率的优化器 optimizer = tf.keras.optimizers.Adam(learning_rate=learning_rate) model.compile( optimizer=optimizer, # 使用自定义优化器 loss='categorical_crossentropy', metrics=['accuracy'] ) model.summary() return model def show_loss_acc(history): acc = history.history['accuracy'] val_acc = history.history['val_accuracy'] loss = history.history['loss'] val_loss = history.history['val_loss'] plt.figure(figsize=(8, 8)) plt.subplot(2, 1, 1) plt.plot(acc, label='Training Accuracy') plt.plot(val_acc, label='Validation Accuracy') plt.legend(loc='lower right') plt.ylabel('Accuracy') plt.ylim([min(plt.ylim()), 1]) plt.title('Training and Validation Accuracy') plt.subplot(2, 1, 2) plt.plot(loss, label='Training Loss') plt.plot(val_loss, label='Validation Loss') plt.legend(loc='upper right') plt.ylabel('Cross Entropy') plt.title('Training and Validation Loss') plt.xlabel('epoch') plt.savefig('results/results_mobilenet.png', dpi=100) def train(epochs): begin_time = time() # 创建必要目录 os.makedirs("models", exist_ok=True) os.makedirs("results", exist_ok=True) try: print("加载数据集中...") train_ds, val_ds = data_load( "C:/Users/dll20/Desktop/vegetables_tf2.3-master/new_data/train", "C:/Users/dll20/Desktop/vegetables_tf2.3-master/new_data/val", 224, 224, 16 ) # 验证数据加载 for images, labels in train_ds.take(1): print(f"图像形状: {images.shape}, 标签形状: {labels.shape}") print(f"标签示例: {labels[0].numpy()}") print("类别数量:", len(label_dict)) print("类别映射:", label_dict) model = model_load(class_num=len(label_dict)) print("开始训练...") history = model.fit( train_ds, validation_data=val_ds, epochs=epochs, verbose=1 ) model.save("models/mobilenet_engineer.h5") show_loss_acc(history) except Exception as e: print(f"训练出错: {str(e)}") import traceback traceback.print_exc() finally: print(f"总耗时: {time() - begin_time:.2f}秒") if __name__ == '__main__': # 配置TensorFlow tf.config.run_functions_eagerly(False) physical_devices = tf.config.list_physical_devices('GPU') if physical_devices: tf.config.experimental.set_memory_growth(physical_devices[0], True) 图像标准化检查: 最小值 = -1.0, 最大值 = 1.0 标签示例: [0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0.] 图像形状: (16, 224, 224, 3), 标签形状: (16, 16) 标签示例: [0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0. 0. 0.] 类别数量: 16 类别映射: {'electrodrill': 0, 'headphones': 1, 'keyboard': 2, 'mobile_phone': 3, 'monitor': 4, 'mouse': 5, 'multimeter': 6, 'number': 7, 'oscillograph': 8, 'pliers': 9, 'printer': 10, 'screwdriver': 11, 'soldering_iron': 12, 'speaker': 13, 'tape_measure': 14, 'wrench': 15} Model: "sequential" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= mobilenetv2_1.00_224 (Functi (None, 7, 7, 1280) 2257984 _________________________________________________________________ global_average_pooling2d (Gl (None, 1280) 0 _________________________________________________________________ dense (Dense) (None, 16) 20496 ================================================================= Total params: 2,278,480 Trainable params: 20,496 Non-trainable params: 2,257,984 _________________________________________________________________ 开始训练... Epoch 1/100 2025-05-17 20:14:57.943383: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cublas64_10.dll 2025-05-17 20:16:05.881342: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library cudnn64_7.dll 2025-05-17 20:19:28.437448: W tensorflow/stream_executor/gpu/redzone_allocator.cc:314] Internal: Invoking GPU asm compilation is supported on Cuda non-Windows platforms only Relying on driver to perform ptx compilation. Modify $PATH to customize ptxas location. This message will be only logged once. 1024/1024 [==============================] - 53s 52ms/step - loss: 9.9016 - accuracy: 0.0606 - val_loss: 9.3069 - val_accuracy: 0.0701 Epoch 2/100 1024/1024 [==============================] - 77s 75ms/step - loss: 10.5672 - accuracy: 0.0642 - val_loss: 10.8782 - val_accuracy: 0.0718 Epoch 3/100 1024/1024 [==============================] - 80s 78ms/step - loss: 10.6035 - accuracy: 0.0639 - val_loss: 10.8998 - val_accuracy: 0.0658 Epoch 4/100 1024/1024 [==============================] - 78s 76ms/step - loss: 10.4597 - accuracy: 0.0658 - val_loss: 9.5053 - val_accuracy: 0.0581 Epoch 5/100 1024/1024 [==============================] - 77s 75ms/step - loss: 10.1673 - accuracy: 0.0596 - val_loss: 12.2643 - val_accuracy: 0.0620 Epoch 6/100 1024/1024 [==============================] - 81s 79ms/step - loss: 10.1886 - accuracy: 0.0628 - val_loss: 9.2048 - val_accuracy: 0.0641 Epoch 7/100 1024/1024 [==============================] - 78s 76ms/step - loss: 10.2992 - accuracy: 0.0630 - val_loss: 10.0681 - val_accuracy: 0.0658 Epoch 8/100 1024/1024 [==============================] - 65s 63ms/step - loss: 10.2812 - accuracy: 0.0665 - val_loss: 12.2382 - val_accuracy: 0.0645 Epoch 9/100 1024/1024 [==============================] - 76s 74ms/step - loss: 11.4436 - accuracy: 0.0637 - val_loss: 9.5845 - val_accuracy: 0.0697 Epoch 10/100 1024/1024 [==============================] - 55s 54ms/step - loss: 10.2822 - accuracy: 0.0664 - val_loss: 9.9871 - val_accuracy: 0.0632 Epoch 11/100 1024/1024 [==============================] - 56s 55ms/step - loss: 10.9518 - accuracy: 0.0647 - val_loss: 12.8353 - val_accuracy: 0.0603 Epoch 12/100 1024/1024 [==============================] - 57s 55ms/step - loss: 10.7480 - accuracy: 0.0646 - val_loss: 10.8068 - val_accuracy: 0.0607 Epoch 13/100 1024/1024 [==============================] - 56s 54ms/step - loss: 10.3040 - accuracy: 0.0618 - val_loss: 11.6900 - val_accuracy: 0.0628 Epoch 14/100 1024/1024 [==============================] - 54s 52ms/step - loss: 10.5912 - accuracy: 0.0630 - val_loss: 14.3563 - val_accuracy: 0.0778 Epoch 15/100 1024/1024 [==============================] - 53s 52ms/step - loss: 10.7772 - accuracy: 0.0635 - val_loss: 11.0138 - val_accuracy: 0.0641 Epoch 16/100 1024/1024 [==============================] - 53s 52ms/step - loss: 10.1329 - accuracy: 0.0651 - val_loss: 11.0438 - val_accuracy: 0.0632 Epoch 17/100 1024/1024 [==============================] - 54s 52ms/step - loss: 10.4157 - accuracy: 0.0617 - val_loss: 11.4240 - val_accuracy: 0.0662 Epoch 18/100 1024/1024 [==============================] - 57s 55ms/step - loss: 10.4042 - accuracy: 0.0635 - val_loss: 11.6729 - val_accuracy: 0.0624 train(epochs=100) 我上述代码运行输出 一共16个类 正确率一直这么低 基本没变化 感觉就是没用上这个模型的感觉 不是微调的问题 我的目的是图像分类出16个种类 帮我检查这个代码 帮我找找原因
05-18
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值