当前位置:首页>python>一天一个Python知识点——Day 154:Keras基础

一天一个Python知识点——Day 154:Keras基础

  • 2026-02-26 19:57:09
一天一个Python知识点——Day 154:Keras基础

一、Keras的设计哲学:开发者体验优先

如果说TensorFlow是工业级的引擎,PyTorch是研究者的手术刀,那么Keras就是深度学习中的乐高积木——它让神经网络的构建变得像搭积木一样直观、快速且充满乐趣。

import matplotlib.pyplot as pltdef keras_philosophy():    """Keras核心设计哲学可视化"""    principles = {        '用户友好''为人类设计,而非为机器',        '模块化''神经网络是层的组合游戏',        '易扩展''新类即新模块,自由生长',        '渐进式''从三行代码到复杂科研,平滑过渡'    }    fig, ax = plt.subplots(figsize=(106))    ax.axis('off')    y_pos = 0.8    for principle, desc in principles.items():        ax.text(0.1, y_pos, f'• {principle}', fontsize=14, fontweight='bold',               transform=ax.transAxes, color='#E44D2E')        ax.text(0.25, y_pos-0.03, desc, fontsize=12               transform=ax.transAxes, color='#555555')        y_pos -= 0.15    ax.text(0.50.1'“从想法到结果的最快路径”'           fontsize=16, style='italic', ha='center',           transform=ax.transAxes, color='#2E86C1')    plt.suptitle('Keras设计哲学', fontsize=18, fontweight='bold')    plt.show()keras_philosophy()

Keras是什么?

Keras是一个用Python编写的高级神经网络API,它不是替代TensorFlow的独立框架,而是在TensorFlow之上构建的接口层。它的使命只有一个:将深度学习的复杂度封装进友好的API中 。

关键认知升级

  • ✅ Keras是TensorFlow的官方高级API(自TF 2.0起)

  • ❌ Keras不是独立的深度学习框架(不再支持Theano/CNTK后端)

  • ✅ tf.keras 是你实际要导入的模块

  • ❌ 独立的keras包 已过时,推荐使用TensorFlow内置版本 


二、Keras安装与环境配置

📦 现代Keras工作流:永远通过TensorFlow导入

def keras_installation_guide():    """Keras安装与验证指南"""    guide = '''━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━【Keras安装三步法】—— 永远通过TensorFlow使用Keras━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━✅ 第一步:安装TensorFlow(Keras自动包含)────────────────────────────────────────   pip install tensorflow   # 或GPU版本   pip install tensorflow[and-cuda]✅ 第二步:验证安装────────────────────────────────────────   import tensorflow as tf   from tensorflow import keras   from tensorflow.keras import layers   print(f"TensorFlow版本: {tf.__version__}")   print(f"Keras版本: {keras.__version__}")   print(f"GPU是否可用: {tf.config.list_physical_devices('GPU')}")✅ 第三步:快速健康检查────────────────────────────────────────   # 创建一个极简模型测试环境   model = keras.Sequential([layers.Dense(10, input_shape=(5,))])   model.compile(optimizer='adam', loss='mse')   print("✓ Keras环境就绪!")━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━⚠️ 注意:请勿单独安装独立的keras包(pip install keras)   在TensorFlow 2.x中,应始终使用 tf.keras━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━    '''    print(guide)keras_installation_guide()

三、Keras的三种模型构建范式

Keras最革命性的贡献在于将神经网络建模抽象为三种清晰可选的范式,覆盖从入门到专家的全光谱需求 。

🧱 1. Sequential API —— 入门者的第一块积木

import tensorflow as tffrom tensorflow.keras import layers, modelsdef sequential_demo():    """Sequential API:层的有序堆叠"""    print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")    print("【Sequential API】—— 适合:线性堆叠、快速原型")    print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")    # 方式一:逐层add(适合动态添加)    model_a = models.Sequential()    model_a.add(layers.Dense(64, activation='relu', input_shape=(784,)))    model_a.add(layers.Dropout(0.2))    model_a.add(layers.Dense(10, activation='softmax'))    # 方式二:列表初始化(结构一目了然)    model_b = models.Sequential([        layers.Conv2D(32, (3,3), activation='relu', input_shape=(28,28,1)),        layers.MaxPooling2D((2,2)),        layers.Conv2D(64, (3,3), activation='relu'),        layers.MaxPooling2D((2,2)),        layers.Flatten(),        layers.Dense(128, activation='relu'),        layers.Dropout(0.5),        layers.Dense(10, activation='softmax')    ])    model_b.summary()    return model_b

🧩 2. Functional API —— 架构师的灵活画笔

def functional_demo():    """Functional API:多输入、多输出、非结构拓扑"""    print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")    print("【Functional API】—— 适合:复杂拓扑、分支、多模态")    print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")    # 典型场景1:双输入模型(文本+图像融合分类)    from tensorflow.keras import Input    # 定义两个独立的输入分支    text_input = Input(shape=(100,), name='text_input')    image_input = Input(shape=(32,32,3), name='image_input')    # 文本处理分支    text_features = layers.Dense(64, activation='relu')(text_input)    # 图像处理分支    x = layers.Conv2D(32, (3,3), activation='relu')(image_input)    x = layers.GlobalAveragePooling2D()(x)    image_features = layers.Dense(64, activation='relu')(x)    # 特征融合    combined = layers.Concatenate()([text_features, image_features])    # 输出层    output = layers.Dense(1, activation='sigmoid', name='output')(combined)    # 定义模型(指定输入和输出)    multi_input_model = models.Model(        inputs=[text_input, image_input],        outputs=output    )    print("✓ 多输入模型构建完成")    print(f"输入: {multi_input_model.input_names}")    print(f"输出: {multi_input_model.output_names}")    # 典型场景2:残差连接(跳层连接)    print("\n【残差连接示例】")    input_tensor = Input(shape=(32,32,3))    # 主路径    x = layers.Conv2D(32, (3,3), padding='same')(input_tensor)    x = layers.BatchNormalization()(x)    x = layers.ReLU()(x)    x = layers.Conv2D(32, (3,3), padding='same')(x)    x = layers.BatchNormalization()(x)    # 残差连接(恒等映射)    residual = layers.Conv2D(32, (1,1), padding='same')(input_tensor)    output_tensor = layers.add([x, residual])    output_tensor = layers.ReLU()(output_tensor)    resnet_block = models.Model(input_tensor, output_tensor)    print("✓ 残差块构建完成(支持任意层数的跳连)")    return multi_input_model# 执行演示functional_demo()

🧪 3. Model Subclassing —— 研究员的自由之地

def subclassing_demo():    """Model Subclassing:完全自定义的前向逻辑"""    print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")    print("【Model Subclassing】—— 适合:科研创新、控制流、动态架构")    print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")    class DynamicRouteNetwork(tf.keras.Model):        """根据输入特征动态选择网络路径"""        def __init__(self, num_classes=10):            super().__init__()            # 定义所有可能的模块            self.conv_path = tf.keras.Sequential([                layers.Conv2D(323, activation='relu'),                layers.GlobalAveragePooling2D()            ])            self.dense_path = tf.keras.Sequential([                layers.Dense(128, activation='relu'),                layers.Dense(64, activation='relu')            ])            self.classifier = layers.Dense(num_classes, activation='softmax')            # 可训练的路由权重            self.route_weight = self.add_weight(                name='route_weight',                shape=(1,),                initializer='zeros',                trainable=True            )        def call(self, inputs, training=None):            # 动态决策:根据输入尺寸选择路径            if len(inputs.shape) == 4:  # 4D张量 → 图像                features = self.conv_path(inputs)            else:  # 2D张量 → 向量                features = self.dense_path(inputs)            # 可根据训练状态调整行为            if training:                # 训练时添加随机噪声增强鲁棒性                features = features + tf.random.normal(tf.shape(features)) * 0.1            return self.classifier(features)    model = DynamicRouteNetwork()    # 测试动态路由    img_input = tf.random.normal((132323))    vec_input = tf.random.normal((1784))    print(f"图像输入 → 输出形状: {model(img_input).shape}")    print(f"向量输入 → 输出形状: {model(vec_input).shape}")    print(f"可训练变量数: {len(model.trainable_variables)}")    return model# 执行演示subclassing_demo()

四、三大API对比与选型指南

维度
SequentialFunctionalSubclassing
代码复杂度
⭐ 极低
⭐⭐ 中等
⭐⭐⭐ 较高
结构可视化
清晰线性
显式图结构
黑箱(需自定义summary)
灵活性
❌ 仅线性堆叠
✅✅ 多输入/输出、分支、残差
✅✅✅ 任意Python控制流
调试难度
难(需重写call)
保存与部署
✅ 完美
✅ 完美
⚠️ 需定义get_config
适用人群
初学者、基准测试
工程师、产品开发
研究员、算法创新
经典场景
LeNet, AlexNet
ResNet, Inception, Transformer
元学习、动态网络

选型金律 :

如果你不确定用哪个 → 用Functional如果你只需要堆叠 → 用Sequential如果你在做科研创新 → 用Subclassing

五、Keras完整实战:从数据到部署

🎯 项目:CIFAR-10图像分类(端到端演示)

import tensorflow as tffrom tensorflow.keras import layers, models, datasets, callbacksimport numpy as npimport matplotlib.pyplot as pltclass KerasCompletePipeline:    """Keras完整工作流演示"""    def __init__(self):        self.model = None        self.history = None    def step1_prepare_data(self):        """步骤1:数据加载与增强"""        print("【步骤1】准备CIFAR-10数据集...")        (x_train, y_train), (x_test, y_test) = datasets.cifar10.load_data()        # 归一化        x_train = x_train.astype('float32') / 255.0        x_test = x_test.astype('float32') / 255.0        # 将标签转换为一维        y_train = y_train.squeeze()        y_test = y_test.squeeze()        # 数据增强(Keras预处理层)        data_augmentation = tf.keras.Sequential([            layers.RandomFlip("horizontal"),            layers.RandomRotation(0.1),            layers.RandomZoom(0.1),            layers.RandomContrast(0.1),        ])        # 构建高效数据管道        train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))        train_dataset = train_dataset.shuffle(10000)        train_dataset = train_dataset.batch(64)        train_dataset = train_dataset.map(            lambda x, y: (data_augmentation(x, training=True), y),            num_parallel_calls=tf.data.AUTOTUNE        )        train_dataset = train_dataset.prefetch(tf.data.AUTOTUNE)        test_dataset = tf.data.Dataset.from_tensor_slices((x_test, y_test))        test_dataset = test_dataset.batch(64).prefetch(tf.data.AUTOTUNE)        print(f"训练集: {x_train.shape}, 测试集: {x_test.shape}")        print(f"数据增强已启用: Flip, Rotation, Zoom, Contrast")        return train_dataset, test_dataset, (x_test, y_test)    def step2_build_model(self):        """步骤2:模型构建(Functional API)"""        print("\n【步骤2】构建卷积神经网络...")        # 输入层        inputs = layers.Input(shape=(32323))        # 卷积基        x = layers.Conv2D(32, (3,3), padding='same')(inputs)        x = layers.BatchNormalization()(x)        x = layers.ReLU()(x)        x = layers.Conv2D(32, (3,3), padding='same')(x)        x = layers.BatchNormalization()(x)        x = layers.ReLU()(x)        x = layers.MaxPooling2D((2,2))(x)        x = layers.Dropout(0.2)(x)        x = layers.Conv2D(64, (3,3), padding='same')(x)        x = layers.BatchNormalization()(x)        x = layers.ReLU()(x)        x = layers.Conv2D(64, (3,3), padding='same')(x)        x = layers.BatchNormalization()(x)        x = layers.ReLU()(x)        x = layers.MaxPooling2D((2,2))(x)        x = layers.Dropout(0.3)(x)        x = layers.Conv2D(128, (3,3), padding='same')(x)        x = layers.BatchNormalization()(x)        x = layers.ReLU()(x)        x = layers.GlobalAveragePooling2D()(x)        x = layers.Dropout(0.4)(x)        # 分类头        x = layers.Dense(128, activation='relu')(x)        x = layers.Dropout(0.5)(x)        outputs = layers.Dense(10, activation='softmax')(x)        model = models.Model(inputs, outputs)        # 编译模型        model.compile(            optimizer=tf.keras.optimizers.Adam(learning_rate=0.001),            loss='sparse_categorical_crossentropy',            metrics=['accuracy'                    tf.keras.metrics.TopKCategoricalAccuracy(k=3, name='top3_acc')]        )        self.model = model        model.summary()        return model    def step3_train(self, train_dataset, val_dataset):        """步骤3:训练与回调"""        print("\n【步骤3】开始训练...")        # 回调函数配置        callbacks_list = [            # 早停(防止过拟合)            callbacks.EarlyStopping(                monitor='val_loss',                patience=10,                restore_best_weights=True,                verbose=1            ),            # 学习率衰减            callbacks.ReduceLROnPlateau(                monitor='val_loss',                factor=0.5,                patience=5,                min_lr=1e-6,                verbose=1            ),            # 模型检查点            callbacks.ModelCheckpoint(                'cifar10_best.h5',                monitor='val_accuracy',                save_best_only=True,                verbose=1            ),            # TensorBoard日志            callbacks.TensorBoard(                log_dir='./logs',                histogram_freq=1,                write_graph=True            ),            # 自定义回调:打印学习率            callbacks.LambdaCallback(                on_epoch_end=lambda epoch, logs:                 print(f"LR: {self.model.optimizer.lr.numpy():.2e}")            )        ]        history = self.model.fit(            train_dataset,            validation_data=val_dataset,            epochs=50,            callbacks=callbacks_list,            verbose=1        )        self.history = history        return history    def step4_evaluate(self, test_data):        """步骤4:评估与可视化"""        print("\n【步骤4】模型评估...")        x_test, y_test = test_data        test_loss, test_acc, test_top3 = self.model.evaluate(x_test, y_test, verbose=0)        print(f"测试集准确率: {test_acc:.4f}")        print(f"测试集Top-3准确率: {test_top3:.4f}")        # 可视化训练历史        self.plot_history()        # 可视化预测结果        self.plot_predictions(x_test, y_test)        return test_acc    def plot_history(self):        """绘制训练曲线"""        fig, axes = plt.subplots(12, figsize=(124))        # 损失曲线        axes[0].plot(self.history.history['loss'], label='训练损失')        axes[0].plot(self.history.history['val_loss'], label='验证损失')        axes[0].set_xlabel('Epoch')        axes[0].set_ylabel('损失')        axes[0].set_title('训练/验证损失')        axes[0].legend()        axes[0].grid(True, alpha=0.3)        # 准确率曲线        axes[1].plot(self.history.history['accuracy'], label='训练准确率')        axes[1].plot(self.history.history['val_accuracy'], label='验证准确率')        axes[1].set_xlabel('Epoch')        axes[1].set_ylabel('准确率')        axes[1].set_title('训练/验证准确率')        axes[1].legend()        axes[1].grid(True, alpha=0.3)        plt.suptitle('CIFAR-10训练历史', fontsize=14, fontweight='bold')        plt.tight_layout()        plt.show()    def plot_predictions(self, x_test, y_test):        """可视化预测结果"""        class_names = ['飞机''汽车''鸟''猫''鹿',                      '狗''青蛙''马''船''卡车']        # 随机选择9张测试图片        indices = np.random.choice(len(x_test), 9, replace=False)        fig, axes = plt.subplots(33, figsize=(99))        for i, ax in enumerate(axes.flat):            idx = indices[i]            img = x_test[idx]            true_label = y_test[idx]            # 预测            pred = self.model.predict(img[np.newaxis, ...], verbose=0)            pred_label = np.argmax(pred)            confidence = np.max(pred)            # 显示图像            ax.imshow(img)            color = 'green' if pred_label == true_label else 'red'            ax.set_title(f'真实:{class_names[true_label]}\n预测:{class_names[pred_label]}({confidence:.2f})',                        color=color, fontsize=10)            ax.axis('off')        plt.suptitle('CIFAR-10预测结果可视化', fontsize=14, fontweight='bold')        plt.tight_layout()        plt.show()    def step5_export(self):        """步骤5:模型导出与部署准备"""        print("\n【步骤5】模型导出...")        # 1. 保存完整模型        self.model.save('cifar10_final.h5')        print("✓ 模型保存为 H5 格式")        # 2. 导出为SavedModel(推荐生产部署)        self.model.export('cifar10_saved_model')        print("✓ 模型导出为 SavedModel 格式")        # 3. 转换为TensorFlow Lite        converter = tf.lite.TFLiteConverter.from_keras_model(self.model)        converter.optimizations = [tf.lite.Optimize.DEFAULT]        tflite_model = converter.convert()        with open('cifar10_model.tflite''wb'as f:            f.write(tflite_model)        print(f"✓ TensorFlow Lite模型已导出 (大小: {len(tflite_model)/1024:.1f} KB)")        return True# ===== 执行完整流程 =====print("=" * 60)print("Keras端到端实战:CIFAR-10图像分类")print("=" * 60)pipeline = KerasCompletePipeline()# 流水线执行train_ds, test_ds, raw_test = pipeline.step1_prepare_data()model = pipeline.step2_build_model()history = pipeline.step3_train(train_ds, test_ds)accuracy = pipeline.step4_evaluate(raw_test)pipeline.step5_export()print("\n✅ Keras完整工作流演示完成!")print(f"最佳验证准确率: {max(history.history['val_accuracy']):.4f}")

六、Keras预训练模型库:站在巨人肩上

Keras最强大的生产力工具之一是 applications 模块,提供20+种SOTA预训练模型,一行代码即可加载 。

def pretrained_demo():    """Keras预训练模型:迁移学习实战"""    print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")    print("【Keras Applications】—— 30秒拥有SOTA模型")    print("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")    from tensorflow.keras import applications    # 1. 加载预训练模型(不包含分类头)    base_model = applications.ResNet50(        weights='imagenet',        include_top=False,  # 移除分类层        input_shape=(2242243),        pooling='avg'       # 全局平均池化    )    # 2. 冻结基干(不参与训练)    base_model.trainable = False    # 3. 添加新的分类头    model = tf.keras.Sequential([        base_model,        layers.Dense(256, activation='relu'),        layers.Dropout(0.5),        layers.Dense(10, activation='softmax')  # 新数据集10类    ])    print(f"基干模型: ResNet50 (ImageNet预训练)")    print(f"基干参数量: {base_model.count_params():,} (已冻结)")    print(f"新增头参数量: {model.layers[-1].count_params():,}")    # 4. 解冻部分层进行微调    print("\n【微调阶段】")    base_model.trainable = True    # 冻结前100层,只微调高层特征    for layer in base_model.layers[:100]:        layer.trainable = False    trainable_count = sum([1 for layer in base_model.layers if layer.trainable])    print(f"解冻层数: {trainable_count}/{len(base_model.layers)}")    return model# 执行演示pretrained_demo()

支持的预训练模型全家桶 :

视觉模型
NLP/序列模型
ResNet50, ResNet101
BERT (通过TF Hub)
EfficientNet B0-B7
GPT (通过TF Hub)
MobileNet V1/V2/V3
Transformer
VGG16, VGG19
Inception V3
DenseNet121,169,201
Xception

七、Keras回调系统:训练时的智能助手

Keras的回调机制是其“开发者体验优先”哲学的极致体现——在训练过程中插入自定义逻辑,像给模型装上智能传感器 。

def custom_callbacks_demo():    """Keras回调系统:训练时的智能干预"""    from tensorflow.keras import callbacks    class CustomCallback(tf.keras.callbacks.Callback):        """自定义回调:监控梯度范数、学习率自适应"""        def __init__(self, patience=3):            super().__init__()            self.patience = patience            self.best_weights = None            self.wait = 0        def on_epoch_begin(self, epoch, logs=None):            # epoch开始时触发            print(f"\n▶️ Epoch {epoch+1} 开始")        def on_batch_end(self, batch, logs=None):            # 每批次结束时监控梯度            if batch % 50 == 0:                # 计算梯度范数                grad_norm = 0                for weight in self.model.trainable_weights:                    if weight._grad is not None:                        grad_norm += tf.norm(weight._grad).numpy()                logs = logs or {}                logs['grad_norm'] = grad_norm                print(f"  批次 {batch}: 损失={logs.get('loss'):.4f}, 梯度范数={grad_norm:.2f}")        def on_epoch_end(self, epoch, logs=None):            # 自动保存最佳模型            current_acc = logs.get('val_accuracy')            if current_acc and current_acc > self.best_acc:                self.best_acc = current_acc                self.best_weights = self.model.get_weights()                self.wait = 0                print(f"⭐ 保存最佳模型,准确率: {current_acc:.4f}")            else:                self.wait += 1    # 官方回调全家桶    standard_callbacks = {        '早停': callbacks.EarlyStopping(monitor='val_loss', patience=5),        '学习率衰减': callbacks.ReduceLROnPlateau(monitor='val_loss', factor=0.5),        '模型检查点': callbacks.ModelCheckpoint('model.h5', save_best_only=True),        'TensorBoard': callbacks.TensorBoard(log_dir='./logs'),        '学习率调度': callbacks.LearningRateScheduler(            lambda epoch: 0.001 * 0.95**epoch        ),        'CSV日志': callbacks.CSVLogger('training.log'),        '终止NaN': callbacks.TerminateOnNaN(),        'Lambda回调': callbacks.LambdaCallback(            on_epoch_end=lambda epoch, logs: print(f"Epoch {epoch} done")        )    }    print("Keras回调系统——训练时的智能传感器")    print("=" * 50)    for name, cb in standard_callbacks.items():        print(f"  • {name}{cb.__class__.__name__}")    return standard_callbackscustom_callbacks_demo()

八、Keras生态定位:深度学习的“普通话”

经过三天的深度学习框架之旅(TF152, PyTorch153, Keras154),是时候理清三者的关系了:

def ecosystem_positioning():    """Keras vs TensorFlow vs PyTorch:共存而非替代"""    positioning = '''━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━【深度学习框架生态定位】—— 工具是为目标服务的━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━🧱 Keras —— 高级API层(抽象程度最高)   ├─ 设计目标:开发者体验、快速迭代、低认知负荷   ├─ 核心价值:3行代码构建神经网络,20+预训练模型   └─ 典型用户:初学者、数据科学家、产品经理⚙️ TensorFlow —— 工业级引擎(抽象程度中等)   ├─ 设计目标:生产部署、端到端生态、跨平台   ├─ 核心价值:TF Serving, TF Lite, TF.js, XLA编译   └─ 典型用户:ML工程师、后端开发者、企业团队🔧 PyTorch —— 科研手术刀(抽象程度较低)   ├─ 设计目标:研究灵活性、动态图、Pythonic   ├─ 核心价值:易于调试、控制流原生、学术界首选   └─ 典型用户:研究员、博士生、算法创新者━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━【选型决策树】问题1:你希望3小时内跑通第一个模型?  →  Keras问题2:你正在做毕设/发论文?          →  PyTorch问题3:你要部署到手机/浏览器?        →  TensorFlow问题4:你需要同时满足研发和生产?     →  Keras建型 + TF部署━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━    '''    print(positioning)ecosystem_positioning()

Keras的伟大之处,不在于它能做别人做不到的事情,而在于它让所有人都能做到以前只有专家才能做的事情。

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-03-01 05:01:58 HTTP/2.0 GET : https://f.mffb.com.cn/a/475361.html
  2. 运行时间 : 0.074477s [ 吞吐率:13.43req/s ] 内存消耗:4,909.41kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=6c47be39bf2af1bf66ca00b8d931e504
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000394s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000771s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000306s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000271s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000597s ]
  6. SELECT * FROM `set` [ RunTime:0.000204s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000589s ]
  8. SELECT * FROM `article` WHERE `id` = 475361 LIMIT 1 [ RunTime:0.000539s ]
  9. UPDATE `article` SET `lasttime` = 1772312518 WHERE `id` = 475361 [ RunTime:0.000782s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000194s ]
  11. SELECT * FROM `article` WHERE `id` < 475361 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000401s ]
  12. SELECT * FROM `article` WHERE `id` > 475361 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000349s ]
  13. SELECT * FROM `article` WHERE `id` < 475361 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.000643s ]
  14. SELECT * FROM `article` WHERE `id` < 475361 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.002091s ]
  15. SELECT * FROM `article` WHERE `id` < 475361 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.000922s ]
0.075991s