tensorflow搭建简单CNN,包括OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already in

csdn参考

数据集简介
Cifar-10 是由 Hinton 的学生 Alex Krizhevsky、Ilya Sutskever 收集的一个用于普适物体识别的计算机视觉数据集,它包含 60000 张 32 X 32 的 RGB 彩色图片,总共 10 个分类。其中,包括 50000 张用于训练集,10000 张用于测试集。

import tensorflow as tf

import numpy as np
from matplotlib import pyplot as plt

np.set_printoptions(threshold=np.inf)

cifar10 = tf.keras.datasets.cifar10
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0


class Baseline(tf.keras.Model):
    def __init__(self):
        super(Baseline, self).__init__()
        #定义了一个卷积层,使用了6个5x5大小的过滤器(filters),并使用'SAME'的填充方式。
        self.c1 = tf.keras.layers.Conv2D(filters=6, kernel_size=(5, 5), padding='same')
        # 定义了一个批归一化层,对卷积层的输出进行归一化处理。
        self.b1 = tf.keras.layers.BatchNormalization()
        # 定义了一个激活函数层,使用ReLU激活函数来增加网络的非线性表达能力。
        self.a1 = tf.keras.layers.Activation('relu')
        # 定义了一个池化层,使用2x2的池化窗口来进行下采样操作。
        self.p1 = tf.keras.layers.MaxPool2D(pool_size=(2, 2), strides=2, padding='same')
        # 定义了一个Dropout层,随机地将输入单元的一部分置为0,以减少过拟合。
        self.d1 = tf.keras.layers.Dropout(0.2)
        # 定义了一个Flatten层,用于将卷积层的输出数据展平,以便后续的全连接层使用。
        self.flatten = tf.keras.layers.Flatten()
        # 定义了一个全连接层,有128个神经元,并使用ReLU激活函数。
        self.f1 = tf.keras.layers.Dense(128, activation='relu')
        self.d2 = tf.keras.layers.Dropout(0.2)
        self.f2 = tf.keras.layers.Dense(10, activation='softmax')

    def call(self, inputs):
        x = self.c1(inputs)
        x = self.b1(x)
        x = self.a1(x)
        x = self.p1(x)
        x = self.d1(x)
        x = self.flatten(x)
        x = self.f1(x)
        x = self.d2(x)
        y = self.f2(x)
        return y


model = Baseline()
model.compile(optimizer=tf.keras.optimizers.Adam(),
              loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False),
              metrics=[tf.keras.metrics.sparse_categorical_accuracy])
history = model.fit(x_train, y_train, batch_size=32, epochs=5, validation_data=(x_test, y_test), validation_freq=1)
model.summary()

# show
acc = history.history['sparse_categorical_accuracy']
val_acc = history.history['val_sparse_categorical_accuracy']
loss = history.history['loss']
val_loss = history.history['val_loss']
print(acc)
print(val_loss)

plt.figure(figsize=(8, 8))
plt.subplot(1, 2, 1)
plt.plot(acc, label='Training Accuracy')
plt.plot(val_acc, label='Validation Accuracy')
plt.title('Training and Validation Accuracy')
plt.legend()

plt.subplot(1, 2, 2)
plt.plot(loss, label='Training loss')
plt.plot(val_loss, label='Validation loss')
plt.title('Training and Validation loss')
plt.legend()
plt.show()

第一次运行报错

OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.

翻译:

OMP:错误#15:初始化libomp5md.dll,但发现libomp5mD.dll已初始化。

OMP:提示这意味着OpenMP运行时的多个副本已链接到程序中。这很危险,因为它会降低性能或导致错误的结果。最好的做法是确保只有一个OpenMP运行时链接到流程中,例如避免在任何库中静态链接OpenMP运行库。作为一种不安全、不受支持、未记录的解决方法,您可以将环境变量KMP_DUPLICATE_LIB_OK=TRUE设置为允许程序继续执行,但这可能会导致崩溃或无声地产生错误结果。有关详细信息,请参阅http://www.intel.com/software/products/support/.

解决:找到 libiomp5md.dll 文件一个一个试,多余删掉

成功运行

打印每一层的名称、输出形状和参数量

 conv2d (Conv2D)             multiple                  456       
                                                                 
 batch_normalization (BatchN  multiple                 24        
 ormalization)                                                   
                                                                 
 activation (Activation)     multiple                  0         
                                                                 
 max_pooling2d (MaxPooling2D  multiple                 0         
 )                                                               
                                                                 
 dropout (Dropout)           multiple                  0         
                                                                 
 flatten (Flatten)           multiple                  0         
                                                                 
 dense (Dense)               multiple                  196736    
                                                                 
 dropout_1 (Dropout)         multiple                  0         
                                                                 
 dense_1 (Dense)             multiple                  1290 
 =============================================================
 Total params: 198,506
Trainable params: 198,494
Non-trainable params: 12
# 其中,可训练的参数量为 198,494,而不可训练的参数量为 12。

打印训练过程中的准确率列表(accuracy)

[0.39452001452445984, 0.4899600148200989, 0.5206400156021118, 0.5406000018119812, 0.553380012512207]

打印验证集损失值列表(validation loss)

[1.7609888315200806, 1.2996513843536377, 1.2674442529678345, 1.2546981573104858, 1.1912604570388794]

在这里插入图片描述

发现该图表现为欠拟合,增加迭代次数 epochs=10,优化一下
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值