【大创】(四)人群异常检测项目过程学习

人群中的异常行为是一大潜在威胁,自动检测监控中的异常行为成为近年的研究热点之一。

一、工具

今天在看github上各位大佬写的关于人群异常检测的代码的时候,发现了一个无敌好用的神器:Google Colab

Colaboratory 简称“Colab”,是Google Research 团队开发的一款产品。 在Colab 中,任何人都可以通过浏览器编写和执行任意Python 代码。 它尤其适合机器学习、数据分析和教育目的。 从技术上说,Colab 是一种托管式Jupyter 笔记本服务。

简单地说,就是一款不需要安装各种机器学习环境的云端Jupyter Notebook!

下面的代码可以轻而易举的在Google Colab上跑通。

二、代码

1.数据准备(生成trainer.npy文件)

我用的数据集来自于Avenue training dataset。下载完成之后,在根目录中的content目录下建立training_videos目录,并把下载好的数据集中的training_videos上传上去。(这里也可以根据自己代码编写的目录上传到不同的目录下)

新建ipynb文件开始编写代码。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
'''
请确保您检查变量video_source_path指向包含训练数据集的文件夹
并确保您上传了正确的培训视频而不是测试视频

'''

from keras.preprocessing.image import img_to_array,load_img
import numpy as np
import glob
import os
from skimage import data, color
from skimage.transform import rescale, resize, downscale_local_mean
#rescale 按一定的因子缩放图像
#resize 调整图像的大小以匹配一定的大小
#downscale_local_mean 通过局部平均下采样N维图像。
import argparse
from PIL import Image
imagestore=[]

video_source_path='/content/training_videos'
#视频的路径
fps=5
#fps是指拍摄一帧的秒数。fps = 5表示每5秒1帧。更像是帧/秒

def create_dir(path):#创建目录
if not os.path.exists(path):#返回布尔值,如果路径存在,返回true,如果不存在,返回false
os.makedirs(path)#如果路径不存在,利用makedirs方法创建目录

def remove_old_images(path):#删除旧的路径下的图片
filelist = glob.glob(os.path.join(path, "*.png"))#filelist用于存储传入路径中的所有图片
#os.path.join()函数用于拼接文件的路径
#glob()函数可以用来查找符合自己目的的文件,返回的文件名只包括当前目录里的文件名,不包括子文件夹里的文件。
for f in filelist:#遍历filelist并删除文件里面的图片
os.remove(f)

def store(image_path):#存储图片
img=load_img(image_path)#对指定image_path的图片进行提取
img=img_to_array(img)#把图片转换为numpy数组

#把图片调整为(227,227,3),以便于网络能够处理它
img=resize(img,(227,227,3))
#将图像转换为灰度图
gray=0.2989*img[:,:,0]+0.5870*img[:,:,1]+0.1140*img[:,:,2]
#存储到ImageStore中
imagestore.append(gray)


#来源于video_source_path中的所有的视频列表
videos=os.listdir(video_source_path)
print("Found ",len(videos)," training videos")#打印结果是找到的视频数量


#创建临时目录存储所有的帧
create_dir(video_source_path+'/frames')

#去除之前的无用图片
remove_old_images(video_source_path+'/frames')

framepath=video_source_path+'/frames'#创建framepath用来存储帧所在的路径

for video in videos:#遍历videos视频列表
os.system( 'ffmpeg -i {}/{} -r 1/{} {}/frames/%03d.jpg'.format(video_source_path,video,fps,video_source_path))
#format用于格式化字符串,这里是把os命令中加入视频路径等信息,format方法中每一个参数对应前面字符串中的一个{}
#os.system用于执行系统命令,这里执行的是ffmpeg
#-i是获取视频文件信息,对应的参数是video_source_path/video(路径)
#-r是设置帧速度。即,每秒提取帧到图像的数字。默认值是25。这里对应的是参数fps
#{}/frames/%03d.jpg 表示如何命名我们提取的图像,对应的参数是video_source_path

images=os.listdir(framepath)#返回framepath指定的文件夹包含的文件或文件夹的名字的列表,存入images中
for image in images:
#遍历images列表,将每张提取出来的帧转换(227,227,3)后转换为灰度图存到ImageStore数组中
image_path=framepath+ '/'+ image
store(image_path)


imagestore=np.array(imagestore)#将imagestore转换为Numpy数组
a,b,c=imagestore.shape#用a,b,c存储数组的维度

#重塑为(227,227,batch_size)
imagestore.resize(b,c,a)
#归一化
imagestore=(imagestore-imagestore.mean())/(imagestore.std())
#处理数组中的负值,0和1是限定的最小值和最大值
imagestore=np.clip(imagestore,0,1)
np.save('trainer.npy',imagestore)#生成训练数据文件
#删除缓冲区目录
os.system('rm -r {}'.format(framepath))#rm -r是指递归删除目录,会事先删除目录中的内容后再删除目录
print("Program ended. Please wait while trainer.npy is created. \nRefresh when needed")
print('Number of frames created :', int(len(imagestore)))#输出处理好的图像数组元素个数

运行结果:

Found 16 training videos

Program ended. Please wait while trainer.npy is created.

Refresh when needed

Number of frames created : 227

因此,现在content目录下已经创建了一个名为trainer.npy的训练数据文件 在进入下一部分之前,请确认其存在。

问题:这里为什么要重塑为(227,227,batch_size)?

2.训练模型(生成AnomalyDetector.h5文件)

现在已经创建了trainer.npy,我们可以运行以下代码并使用它来生成异常检测器模型。这样创建的模型将称为AnomalyDetector.h5。

相关函数解释:

keras.callbacks:
  • ```python ModelCheckpoint( filepath, monitor='val_loss', verbose=0, save_best_only=False, save_weights_only=False, mode='auto', period=1 )

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31

    用于在每个训练期之后保存模型

    - filepath:字符串,保存模型的路径。

    - monitor:被监测的数据。

    - verbose:详细信息模式,0或者1 。

    - save_best_only: 如果save_best_only=True,被监测数据的最佳模型就不会被覆盖。

    - mode:{auto, min, max}的其中之一。

    如果save_best_only=True,那么是否覆盖保存文件的决定就取决于被监测数据的最大或者最小值。

    对于val_acc,模式就会是max,而对于val_loss,模式就需要是min,等等。

    在auto模式中,方向会自动从被监测的数据的名字中判断出来。

    - save_weights_only:如果True,那么只有模型的权重会被保存(model.save_weights(filepath)),否则的话,整个模型会被保存 (model.save(filepath))。

    - period:每个检查点之间的间隔(训练轮数)。

    - ```python
    EarlyStopping(
    monitor='val_loss',
    min_delta=0, patience=0,
    verbose=0, mode='auto',
    baseline=None,
    restore_best_weights=False
    )

    当被监测的数量不再提升,则停止训练。

    • monitor:被监测的数据。

    • min_delta:在被监测的数据中被认为是提升的最小变化,例如,小于min_delta的绝对变化会被认为没有提升。

    • patience:没有进步的训练轮数,在这之后训练就会被停止。

    • verbose:详细信息模式。

    • mode:{auto, min, max}其中之一。

      在min模式中,当被监测的数据停止下降,训练就会停止;

      在max模式中,当被监测的数据停止上升,训练就会停止;

      在auto模式中,方向会自动从被监测的数据的名字中判断出来。

    • baseline:要监控的数量的基准值.如果模型没有显示基准的改善,训练将停止。

    • restore_best_weights:是否从具有监测数量的最佳值的时期恢复模型权重。如果为False,则使用在训练的最后一步获得的模型权重。

keras.layers:
  • ```python Conv3D( filters, kernel_size, strides=(1, 1, 1), padding='valid', data_format=None, dilation_rate=(1, 1, 1), activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None )

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48

    三维卷积对三维的输入进行滑动窗卷积,当使用该层作为第一层时,应提供`input_shape`参数。例如`input_shape = (3,10,128,128)`代表对10帧128*128的彩色RGB图像进行卷积。数据的通道位置仍然有`data_format`参数指定。

    - filters:卷积核的数目(即输出的维度)
    - kernel_size:一个整数,或者3 个整数表示的元组或列表, 指明3D 卷积窗口的深度、高度和宽度。 可以是一个整数,为所有空间维度指定相同的值。
    - strides:单个整数或由3个整数构成的list/tuple,为卷积的步长。如为单个整数,则表示在各个空间维度的相同步长。任何不为1的strides均与任何不为1的dilation_rate均不兼容
    - padding:补0策略,为“valid”, “same” 。“valid”代表只进行有效的卷积,即对边界数据不处理。“same”代表保留边界处的卷积结果,通常会导致输出shape与输入shape相同。
    - activation:激活函数,为预定义的激活函数名(参考[激活函数](https://keras-cn.readthedocs.io/en/latest/other/activations)),或逐元素(element-wise)的Theano函数。如果不指定该参数,将不会使用任何激活函数(即使用线性激活函数:a(x)=x)
    - dilation_rate:单个整数或由3个个整数构成的list/tuple,指定dilated convolution中的膨胀比例。任何不为1的dilation_rate均与任何不为1的strides均不兼容。
    - data_format:字符串,“channels_first”或“channels_last”之一,代表数据的通道维的位置。该参数是Keras 1.x中的image_dim_ordering,“channels_last”对应原本的“tf”,“channels_first”对应原本的“th”。以128x128x128的数据为例,“channels_first”应将数据组织为(3,128,128,128),而“channels_last”应将数据组织为(128,128,128,3)。该参数的默认值是`~/.keras/keras.json`中设置的值,若从未设置过,则为“channels_last”。
    - use_bias:布尔值,是否使用偏置项
    - kernel_initializer:权值初始化方法,为预定义初始化方法名的字符串,或用于初始化权重的初始化器。参考[initializers](https://keras-cn.readthedocs.io/en/latest/other/initializations)
    - bias_initializer:权值初始化方法,为预定义初始化方法名的字符串,或用于初始化权重的初始化器。参考[initializers](https://keras-cn.readthedocs.io/en/latest/other/initializations)
    - kernel_regularizer:施加在权重上的正则项,为[Regularizer](https://keras-cn.readthedocs.io/en/latest/other/regularizers)对象
    - bias_regularizer:施加在偏置向量上的正则项,为[Regularizer](https://keras-cn.readthedocs.io/en/latest/other/regularizers)对象
    - activity_regularizer:施加在输出上的正则项,为[Regularizer](https://keras-cn.readthedocs.io/en/latest/other/regularizers)对象
    - kernel_constraints:施加在权重上的约束项,为[Constraints](https://keras-cn.readthedocs.io/en/latest/other/constraints)对象
    - bias_constraints:施加在偏置上的约束项,为[Constraints](https://keras-cn.readthedocs.io/en/latest/other/constraints)对象

    - ```python
    ConvLSTM2D(
    filters,
    kernel_size,
    strides=(1, 1),
    padding="valid",
    data_format=None,
    dilation_rate=(1, 1),
    activation="tanh",
    recurrent_activation="hard_sigmoid",
    use_bias=True,
    kernel_initializer="glorot_uniform",
    recurrent_initializer="orthogonal",
    bias_initializer="zeros",
    unit_forget_bias=True,
    kernel_regularizer=None,
    recurrent_regularizer=None,
    bias_regularizer=None,
    activity_regularizer=None,
    kernel_constraint=None,
    recurrent_constraint=None,
    bias_constraint=None,
    return_sequences=False,
    go_backwards=False,
    stateful=False,
    dropout=0.0,
    recurrent_dropout=0.0,
    **kwargs
    )

    卷积LSTM。它类似于LSTM层,但是输入转换和递归转换都是卷积的。

    • filter:整数,输出空间的维数(即卷积中输出过滤器的数量)。
    • kernel_size:一个整数或n个整数的元组/列表,指定卷积窗口的尺寸。
    • strides:整数或n个整数的元组/列表,指定卷积的步幅。指定任何跨步值!= 1与指定任何dilation_rate值!= 1 不兼容。
    • padding:"valid""same"(不区分大小写)之一。
    • data_format:字符串,channels_last(默认)或之一channels_first。输入中尺寸的顺序。 channels_last对应于具有形状的输入, (batch, time, ..., channels)channels_first对应于具有形状的输入(batch, time, channels, ...)。默认为image_data_format在Keras配置文件中找到的值~/.keras/keras.json。如果你从未设置,那么它将是“ channels_last”。
    • dilation_rate:一个整数或n个整数的元组/列表,指定用于膨胀卷积的膨胀率。当前,指定任何dilation_rate值!= 1与指定任何strides值!= 1 不兼容。
    • activation:要使用的激活功能。默认情况下,将应用双曲线切线激活函数(tanh(x))。
    • recurrent_activation:用于循环步骤的激活函数。
    • use_bias:布尔值,层是否使用偏置向量。
    • kernel_initializer:kernel权重矩阵的初始化程序,用于输入的线性转换。
    • recurrent_initializer:recurrent_kernel 权重矩阵的初始化程序,用于循环状态的线性转换。
    • bias_initializer:偏差向量的初始化器。
    • unit_forget_bias:布尔值。如果为True,则在初始化时将1加到忘记门的偏置上。与结合使用bias_initializer="zeros"Jozefowicz等人(2015)建议使用
    • kernel_regularizer:将正则化函数应用于kernel权重矩阵。
    • recurrent_regularizer:正则化函数应用于recurrent_kernel权重矩阵。
    • bias_regularizer:将正则化函数应用于偏差向量。
    • activity_regularizer:应用于正则函数。
    • kernel_constraint:应用于kernel权重矩阵的约束函数。
    • recurrent_constraint:应用于recurrent_kernel权重矩阵的约束函数。
    • bias_constraint:应用于偏差向量的约束函数。
    • return_sequences:布尔值。是返回输出序列中的最后一个输出还是完整序列。
    • go_backwards:布尔值(默认为False)。如果为True,则向后处理输入序列。
    • stateful:布尔值(默认为False)。如果为True,则批次中索引i的每个样本的最后状态将用作下一个批次中索引i的样本的初始状态。
    • dropout:在0到1之间浮动。输入线性转换要下降的单位的分数。
    • recurrent_dropout:在0到1之间浮动。在递归状态的线性转换中要下降的单位的分数。
  • ```python Conv3DTranspose( filters, kernel_size, strides=(1, 1, 1), padding="valid", output_padding=None, data_format=None, dilation_rate=(1, 1, 1), activation=None, use_bias=True, kernel_initializer="glorot_uniform", bias_initializer="zeros", kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, bias_constraint=None, **kwargs )

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39

    转置3D卷积层(有时称为3D解卷积)。

    - filters:整数,输出空间的维数(即卷积中的滤波器数).
    - kernel_size:3个整数的整数或元组/列表,指定3D卷积窗口的深度,高度和宽度;可以是单个整数,以指定所有空间维度的相同值.
    - strides:3个整数的整数或元组/列表,指定沿深度,高度和宽度的卷积的步幅;可以是单个整数,以指定所有空间维度的相同值.
    - padding:可以是一个"valid"或"same"(不区分大小写).
    - data_format:一个字符串,可以为channels_last(默认)或channels_first,表示输入中维度的顺序,channels_last对应于具有形状(batch, depth, height, width, channels)的输入,而channels_first对应于具有形状(batch, channels, depth, height, width)的输入.
    - dilation_rate:一个整数或3个整数的元组/列表,指定用于扩张卷积的扩张率。可以是单个整数,以为所有空间尺寸指定相同的值。当前,指定任何`dilation_rate`值!= 1与指定任何步幅值!= 1不兼容。
    - activation:激活功能.将其设置为None以保持线性激活.
    - use_bias:Boolean,该层是否使用偏差.
    - kernel_initializer:卷积内核的初始化程序.
    - bias_initializer:偏置向量的初始化器,如果为None,将使用默认初始值设定项.
    - kernel_regularizer:卷积内核的可选正则化器.
    - bias_regularizer:偏置矢量的可选正则化器.
    - activity_regularizer:输出的可选正则化函数.
    - kernel_constraint:由Optimizer更新后应用于内核的可选投影函数(例如,用于实现层权重的范数约束或值约束).该函数必须将未投影的变量作为输入,并且必须返回投影变量(必须具有相同的形状).在进行异步分布式培训时,使用约束是不安全的.
    - bias_constraint:由Optimizer更新后应用于偏差的可选投影函数.
    - trainable:Boolean,如果为True还将变量添加到图集合GraphKeys.TRAINABLE_VARIABLES中(请参阅参考资料tf.Variable).
    - name:字符串,图层的名称.

    - ```python
    model.fit(
    self,
    x=None,
    y=None,
    batch_size=None,
    epochs=1,
    verbose=1,
    callbacks=None,
    validation_split=0.0,
    validation_data=None,
    shuffle=True,
    class_weight=None,
    sample_weight=None,
    initial_epoch=0,
    steps_per_epoch=None,
    validation_steps=None
    )

    • x:输入数据。如果模型只有一个输入,那么x的类型是numpy array,如果模型有多个输入,那么x的类型应当为list,list的元素是对应于各个输入的numpy array。如果模型的每个输入都有名字,则可以传入一个字典,将输入名与其输入数据对应起来。
    • y:标签,numpy array。如果模型有多个输出,可以传入一个numpy array的list。如果模型的输出拥有名字,则可以传入一个字典,将输出名与其标签对应起来。
    • batch_size:整数,指定进行梯度下降时每个batch包含的样本数。训练时一个batch的样本会被计算一次梯度下降,使目标函数优化一步。
    • epochs:整数,训练终止时的epoch值,训练将在达到该epoch值时停止,当没有设置initial_epoch时,它就是训练的总轮数,否则训练的总轮数为epochs - inital_epoch
    • verbose:日志显示,0为不在标准输出流输出日志信息,1为输出进度条记录,2为每个epoch输出一行记录
    • callbacks:list,其中的元素是keras.callbacks.Callback的对象。这个list中的回调函数将会在训练过程中的适当时机被调用,参考回调函数
    • validation_split:0~1之间的浮点数,用来指定训练集的一定比例数据作为验证集。验证集将不参与训练,并在每个epoch结束后测试的模型的指标,如损失函数、精确度等。注意,validation_split的划分在shuffle之后,因此如果你的数据本身是有序的,需要先手工打乱再指定validation_split,否则可能会出现验证集样本不均匀。
    • validation_data:形式为(X,y)或(X,y,sample_weights)的tuple,是指定的验证集。此参数将覆盖validation_spilt。
    • shuffle:布尔值,表示是否在训练过程中每个epoch前随机打乱输入样本的顺序。
    • class_weight:字典,将不同的类别映射为不同的权值,该参数用来在训练过程中调整损失函数(只能用于训练)。该参数在处理非平衡的训练数据(某些类的训练样本数很少)时,可以使得损失函数对样本数不足的数据更加关注。
    • sample_weight:权值的numpy array,用于在训练时调整损失函数(仅用于训练)。可以传递一个1D的与样本等长的向量用于对样本进行1对1的加权,或者在面对时序数据时,传递一个的形式为(samples,sequence_length)的矩阵来为每个时间步上的样本赋不同的权。这种情况下请确定在编译模型时添加了sample_weight_mode='temporal'
    • initial_epoch: 从该参数指定的epoch开始训练,在继续之前的训练时有用。
    • steps_per_epoch: 一个epoch包含的步数(每一步是一个batch的数据送入),当使用如TensorFlow数据Tensor之类的输入张量进行训练时,默认的None代表自动分割,即数据集样本数/batch样本数。
    • validation_steps: 仅当steps_per_epoch被指定时有用,在验证集上的step总数。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from keras.callbacks import ModelCheckpoint, EarlyStopping
#ModelCheckpoint(filepath, monitor='val_loss', verbose=0, save_best_only=False, save_weights_only=False, mode='auto', period=1)
#用于在每个训练期之后保存模型
#EarlyStopping(monitor='val_loss', min_delta=0, patience=0, verbose=0, mode='auto', baseline=None, restore_best_weights=False)
#当被监测的数量不再提升,则停止训练。
import numpy as np
import argparse
from keras.layers import Conv3D,ConvLSTM2D,Conv3DTranspose
#COnv3D三维卷积
#ConvLSTM2D 卷积LSTM。它类似于LSTM层,但是输入转换和递归转换都是卷积的。
#Conv3DTranspose 转置3D卷积层(有时称为3D解卷积).
from keras.models import Sequential
#Sequential顺序模型是多个网络层的线性堆叠。

#load_model是用的别人的:----------------------------------------------------
def load_model():
"""
返回用于异常事件的模型
使用时空自动编码器检测视频

"""
model=Sequential()#创建一个顺序模型
model.add(Conv3D(filters=128,kernel_size=(11,11,1),strides=(4,4,1),padding='valid',input_shape=(227,227,10,1),activation='tanh'))
#128层过滤器,3D卷积窗口的深度、高度、宽度为(11,11,1),沿深度、高度、宽度的步长为(4,4,1),padding为不填充,input_shape指定输入
model.add(Conv3D(filters=64,kernel_size=(5,5,1),strides=(2,2,1),padding='valid',activation='tanh'))
#使用add方法将各层添加到模型中


model.add(ConvLSTM2D(filters=64,kernel_size=(3,3),strides=1,padding='same',dropout=0.4,recurrent_dropout=0.3,return_sequences=True))

model.add(ConvLSTM2D(filters=32,kernel_size=(3,3),strides=1,padding='same',dropout=0.3,return_sequences=True))

model.add(ConvLSTM2D(filters=64,kernel_size=(3,3),strides=1,return_sequences=True, padding='same',dropout=0.5))

model.add(Conv3DTranspose(filters=128,kernel_size=(5,5,1),strides=(2,2,1),padding='valid',activation='tanh'))
model.add(Conv3DTranspose(filters=1,kernel_size=(11,11,1),strides=(4,4,1),padding='valid',activation='tanh'))

model.compile(optimizer='adam',loss='mean_squared_error',metrics=['accuracy'])
#optimizer=优化器,loss=损失函数(这里用的均方误差),metrics包含评估模型在训练和测试时的性能的指标,常用方法是metrics=['accuracy']
return model

#load_model ends here :----------------------------------------------------

X_train=np.load('trainer.npy')#读取trainer中的数据存入X_train
frames=X_train.shape[2]#帧数是读取数据中的第三维

#需要将帧数除以10以减轻load_model
#Need to make number of frames divisible by 10 to ease the load_model
frames=frames-frames%10

X_train=X_train[:,:,:frames]
X_train=X_train.reshape(-1,227,227,10)
#对数组重新分割,后三个维度分别为227,227,10
#数组新的shape属性应该要与原来的配套,如果等于-1的话,那么Numpy会根据剩下的维度计算出数组的另外一个shape属性值。
X_train=np.expand_dims(X_train,axis=4)
#扩展维度,np.expand_dims(a,axis=)即在a的相应的axis轴上扩展维度,这里是在X_train的第四个维度上再分一次,分出第五个维度
Y_train=X_train.copy()


epochs=200#迭代次数,也就是全数据集
batch_size=1#批尺寸,决定的是下降的方向。batch_Size=1,是在线学习(Online Learning),比较通俗的说就是每次处理多少个数据集,可以合理利用内存容量



if __name__=="__main__":
#前面都是加载过程
model=load_model()#处理数据返回异常行为模型

callback_save = ModelCheckpoint("AnomalyDetector.h5",
monitor="mean_squared_error")#保存模型

callback_early_stopping = EarlyStopping(monitor='val_loss', patience=3)#检测数量不再提升后停止

print('Trainer has been loaded')
#开始训练
model.fit(X_train,Y_train,
batch_size=batch_size,
epochs=epochs,
callbacks = [callback_save,callback_early_stopping]
)
#x表示输入数据,y是它的对应的标签,callbacks表示训练过程中调用的函数
print('Done\n Please wait while AnomalyDetector.h5 has been created \nRefresh when needed')

这部分代码跑的时间比较长,结果:

Trainer has been loaded Epoch 1/200 22/22 [==============================] - 58s 2s/step - loss: 0.2591 - accuracy: 0.5241 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 2/200 22/22 [==============================] - 52s 2s/step - loss: 0.2062 - accuracy: 0.5479 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 3/200 22/22 [==============================] - 52s 2s/step - loss: 0.1938 - accuracy: 0.5523 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 4/200 22/22 [==============================] - 51s 2s/step - loss: 0.1276 - accuracy: 0.6697 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 5/200 22/22 [==============================] - 51s 2s/step - loss: 0.1060 - accuracy: 0.6921 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 6/200 22/22 [==============================] - 52s 2s/step - loss: 0.0933 - accuracy: 0.7107 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 7/200 22/22 [==============================] - 52s 2s/step - loss: 0.0881 - accuracy: 0.7173 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 8/200 22/22 [==============================] - 52s 2s/step - loss: 0.0863 - accuracy: 0.7199 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 9/200 22/22 [==============================] - 52s 2s/step - loss: 0.0855 - accuracy: 0.7160 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 10/200 22/22 [==============================] - 52s 2s/step - loss: 0.0817 - accuracy: 0.7263 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 11/200 22/22 [==============================] - 52s 2s/step - loss: 0.0819 - accuracy: 0.7235 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 12/200 22/22 [==============================] - 52s 2s/step - loss: 0.0799 - accuracy: 0.7241 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 13/200 22/22 [==============================] - 53s 2s/step - loss: 0.0791 - accuracy: 0.7251 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 14/200 22/22 [==============================] - 53s 2s/step - loss: 0.0791 - accuracy: 0.7229 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 15/200 22/22 [==============================] - 53s 2s/step - loss: 0.0795 - accuracy: 0.7234 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 16/200 22/22 [==============================] - 51s 2s/step - loss: 0.0765 - accuracy: 0.7293 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 17/200 22/22 [==============================] - 52s 2s/step - loss: 0.0777 - accuracy: 0.7239 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 18/200 22/22 [==============================] - 53s 2s/step - loss: 0.0773 - accuracy: 0.7268 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 19/200 22/22 [==============================] - 52s 2s/step - loss: 0.0767 - accuracy: 0.7295 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 20/200 22/22 [==============================] - 53s 2s/step - loss: 0.0754 - accuracy: 0.7299 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 21/200 22/22 [==============================] - 53s 2s/step - loss: 0.0771 - accuracy: 0.7291 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 22/200 22/22 [==============================] - 53s 2s/step - loss: 0.0735 - accuracy: 0.7335 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 23/200 22/22 [==============================] - 52s 2s/step - loss: 0.0747 - accuracy: 0.7335 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 24/200 22/22 [==============================] - 52s 2s/step - loss: 0.0736 - accuracy: 0.7361 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 25/200 22/22 [==============================] - 52s 2s/step - loss: 0.0733 - accuracy: 0.7329 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 26/200 22/22 [==============================] - 53s 2s/step - loss: 0.0734 - accuracy: 0.7306 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 27/200 22/22 [==============================] - 52s 2s/step - loss: 0.0736 - accuracy: 0.7316 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 28/200 22/22 [==============================] - 53s 2s/step - loss: 0.0710 - accuracy: 0.7354 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 29/200 22/22 [==============================] - 52s 2s/step - loss: 0.0714 - accuracy: 0.7377 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 30/200 22/22 [==============================] - 53s 2s/step - loss: 0.0708 - accuracy: 0.7388 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 31/200 22/22 [==============================] - 53s 2s/step - loss: 0.0709 - accuracy: 0.7371 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 32/200 22/22 [==============================] - 53s 2s/step - loss: 0.0696 - accuracy: 0.7407 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 33/200 22/22 [==============================] - 52s 2s/step - loss: 0.0714 - accuracy: 0.7342 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 34/200 22/22 [==============================] - 52s 2s/step - loss: 0.0714 - accuracy: 0.7319 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 35/200 22/22 [==============================] - 53s 2s/step - loss: 0.0704 - accuracy: 0.7352 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 36/200 22/22 [==============================] - 53s 2s/step - loss: 0.0688 - accuracy: 0.7380 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 37/200 22/22 [==============================] - 53s 2s/step - loss: 0.0702 - accuracy: 0.7359 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 38/200 22/22 [==============================] - 53s 2s/step - loss: 0.0697 - accuracy: 0.7368 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 39/200 22/22 [==============================] - 52s 2s/step - loss: 0.0690 - accuracy: 0.7377 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 40/200 22/22 [==============================] - 53s 2s/step - loss: 0.0704 - accuracy: 0.7336 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 41/200 22/22 [==============================] - 54s 2s/step - loss: 0.0697 - accuracy: 0.7351 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 42/200 22/22 [==============================] - 53s 2s/step - loss: 0.0695 - accuracy: 0.7371 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 43/200 22/22 [==============================] - 53s 2s/step - loss: 0.0682 - accuracy: 0.7411 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 44/200 22/22 [==============================] - 53s 2s/step - loss: 0.0681 - accuracy: 0.7399 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 45/200 22/22 [==============================] - 53s 2s/step - loss: 0.0696 - accuracy: 0.7362 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 46/200 22/22 [==============================] - 53s 2s/step - loss: 0.0691 - accuracy: 0.7376 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 47/200 22/22 [==============================] - 53s 2s/step - loss: 0.0685 - accuracy: 0.7373 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 48/200 22/22 [==============================] - 53s 2s/step - loss: 0.0691 - accuracy: 0.7393 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 49/200 22/22 [==============================] - 53s 2s/step - loss: 0.0685 - accuracy: 0.7392 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 50/200 22/22 [==============================] - 52s 2s/step - loss: 0.0678 - accuracy: 0.7379 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 51/200 22/22 [==============================] - 52s 2s/step - loss: 0.0691 - accuracy: 0.7363 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 52/200 22/22 [==============================] - 55s 3s/step - loss: 0.0703 - accuracy: 0.7344 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 53/200 22/22 [==============================] - 54s 2s/step - loss: 0.0690 - accuracy: 0.7366 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 54/200 22/22 [==============================] - 53s 2s/step - loss: 0.0686 - accuracy: 0.7357 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 55/200 22/22 [==============================] - 53s 2s/step - loss: 0.0699 - accuracy: 0.7365 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 56/200 22/22 [==============================] - 53s 2s/step - loss: 0.0679 - accuracy: 0.7403 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 57/200 22/22 [==============================] - 53s 2s/step - loss: 0.0689 - accuracy: 0.7367 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 58/200 22/22 [==============================] - 53s 2s/step - loss: 0.0690 - accuracy: 0.7365 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 59/200 22/22 [==============================] - 53s 2s/step - loss: 0.0695 - accuracy: 0.7346 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 60/200 22/22 [==============================] - 54s 2s/step - loss: 0.0687 - accuracy: 0.7353 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 61/200 22/22 [==============================] - 53s 2s/step - loss: 0.0702 - accuracy: 0.7347 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 62/200 22/22 [==============================] - 53s 2s/step - loss: 0.0678 - accuracy: 0.7405 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 63/200 22/22 [==============================] - 53s 2s/step - loss: 0.0697 - accuracy: 0.7384 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 64/200 22/22 [==============================] - 53s 2s/step - loss: 0.0685 - accuracy: 0.7382 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 65/200 22/22 [==============================] - 52s 2s/step - loss: 0.0690 - accuracy: 0.7360 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 66/200 22/22 [==============================] - 52s 2s/step - loss: 0.0686 - accuracy: 0.7368 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 67/200 22/22 [==============================] - 52s 2s/step - loss: 0.0694 - accuracy: 0.7333 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 68/200 22/22 [==============================] - 53s 2s/step - loss: 0.0689 - accuracy: 0.7375 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 69/200 22/22 [==============================] - 53s 2s/step - loss: 0.0683 - accuracy: 0.7358 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 70/200 22/22 [==============================] - 53s 2s/step - loss: 0.0671 - accuracy: 0.7385 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 71/200 22/22 [==============================] - 52s 2s/step - loss: 0.0670 - accuracy: 0.7417 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 72/200 22/22 [==============================] - 52s 2s/step - loss: 0.0672 - accuracy: 0.7405 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 73/200 22/22 [==============================] - 53s 2s/step - loss: 0.0679 - accuracy: 0.7402 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 74/200 22/22 [==============================] - 52s 2s/step - loss: 0.0674 - accuracy: 0.7393 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 75/200 22/22 [==============================] - 53s 2s/step - loss: 0.0666 - accuracy: 0.7401 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 76/200 22/22 [==============================] - 53s 2s/step - loss: 0.0676 - accuracy: 0.7374 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 77/200 22/22 [==============================] - 52s 2s/step - loss: 0.0670 - accuracy: 0.7386 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 78/200 22/22 [==============================] - 53s 2s/step - loss: 0.0675 - accuracy: 0.7376 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 79/200 22/22 [==============================] - 52s 2s/step - loss: 0.0668 - accuracy: 0.7401 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 80/200 22/22 [==============================] - 52s 2s/step - loss: 0.0675 - accuracy: 0.7358 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 81/200 22/22 [==============================] - 52s 2s/step - loss: 0.0668 - accuracy: 0.7397 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 82/200 22/22 [==============================] - 52s 2s/step - loss: 0.0676 - accuracy: 0.7360 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 83/200 22/22 [==============================] - 52s 2s/step - loss: 0.0670 - accuracy: 0.7393 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 84/200 22/22 [==============================] - 53s 2s/step - loss: 0.0668 - accuracy: 0.7357 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 85/200 22/22 [==============================] - 52s 2s/step - loss: 0.0675 - accuracy: 0.7358 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 86/200 22/22 [==============================] - 52s 2s/step - loss: 0.0663 - accuracy: 0.7388 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 87/200 22/22 [==============================] - 53s 2s/step - loss: 0.0672 - accuracy: 0.7378 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 88/200 22/22 [==============================] - 53s 2s/step - loss: 0.0671 - accuracy: 0.7373 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 89/200 22/22 [==============================] - 52s 2s/step - loss: 0.0672 - accuracy: 0.7377 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 90/200 22/22 [==============================] - 52s 2s/step - loss: 0.0670 - accuracy: 0.7374 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 91/200 22/22 [==============================] - 53s 2s/step - loss: 0.0671 - accuracy: 0.7376 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 92/200 22/22 [==============================] - 53s 2s/step - loss: 0.0657 - accuracy: 0.7400 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 93/200 22/22 [==============================] - 53s 2s/step - loss: 0.0654 - accuracy: 0.7394 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 94/200 22/22 [==============================] - 52s 2s/step - loss: 0.0651 - accuracy: 0.7399 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 95/200 22/22 [==============================] - 53s 2s/step - loss: 0.0661 - accuracy: 0.7412 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 96/200 22/22 [==============================] - 52s 2s/step - loss: 0.0671 - accuracy: 0.7338 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 97/200 22/22 [==============================] - 53s 2s/step - loss: 0.0648 - accuracy: 0.7411 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 98/200 22/22 [==============================] - 53s 2s/step - loss: 0.0655 - accuracy: 0.7394 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 99/200 22/22 [==============================] - 53s 2s/step - loss: 0.0656 - accuracy: 0.7375 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 100/200 22/22 [==============================] - 52s 2s/step - loss: 0.0656 - accuracy: 0.7406 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 101/200 22/22 [==============================] - 52s 2s/step - loss: 0.0657 - accuracy: 0.7365 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 102/200 22/22 [==============================] - 52s 2s/step - loss: 0.0645 - accuracy: 0.7396 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 103/200 22/22 [==============================] - 53s 2s/step - loss: 0.0659 - accuracy: 0.7388 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 104/200 22/22 [==============================] - 53s 2s/step - loss: 0.0637 - accuracy: 0.7420 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 105/200 22/22 [==============================] - 53s 2s/step - loss: 0.0648 - accuracy: 0.7378 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 106/200 22/22 [==============================] - 52s 2s/step - loss: 0.0629 - accuracy: 0.7411 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 107/200 22/22 [==============================] - 52s 2s/step - loss: 0.0621 - accuracy: 0.7416 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 108/200 22/22 [==============================] - 52s 2s/step - loss: 0.0604 - accuracy: 0.7410 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 109/200 22/22 [==============================] - 53s 2s/step - loss: 0.0574 - accuracy: 0.7445 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 110/200 22/22 [==============================] - 53s 2s/step - loss: 0.0562 - accuracy: 0.7452 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 111/200 22/22 [==============================] - 53s 2s/step - loss: 0.0544 - accuracy: 0.7470 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 112/200 22/22 [==============================] - 52s 2s/step - loss: 0.0529 - accuracy: 0.7455 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 113/200 22/22 [==============================] - 52s 2s/step - loss: 0.0519 - accuracy: 0.7469 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 114/200 22/22 [==============================] - 52s 2s/step - loss: 0.0512 - accuracy: 0.7502 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 115/200 22/22 [==============================] - 53s 2s/step - loss: 0.0492 - accuracy: 0.7527 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 116/200 22/22 [==============================] - 53s 2s/step - loss: 0.0489 - accuracy: 0.7526 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 117/200 22/22 [==============================] - 52s 2s/step - loss: 0.0482 - accuracy: 0.7511 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 118/200 22/22 [==============================] - 53s 2s/step - loss: 0.0456 - accuracy: 0.7562 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 119/200 22/22 [==============================] - 53s 2s/step - loss: 0.0441 - accuracy: 0.7588 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 120/200 22/22 [==============================] - 53s 2s/step - loss: 0.0431 - accuracy: 0.7590 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 121/200 22/22 [==============================] - 53s 2s/step - loss: 0.0424 - accuracy: 0.7606 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 122/200 22/22 [==============================] - 53s 2s/step - loss: 0.0412 - accuracy: 0.7606 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 123/200 22/22 [==============================] - 53s 2s/step - loss: 0.0401 - accuracy: 0.7647 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 124/200 22/22 [==============================] - 53s 2s/step - loss: 0.0394 - accuracy: 0.7637 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 125/200 22/22 [==============================] - 53s 2s/step - loss: 0.0386 - accuracy: 0.7674 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 126/200 22/22 [==============================] - 52s 2s/step - loss: 0.0377 - accuracy: 0.7664 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 127/200 22/22 [==============================] - 52s 2s/step - loss: 0.0371 - accuracy: 0.7705 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 128/200 22/22 [==============================] - 52s 2s/step - loss: 0.0375 - accuracy: 0.7655 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 129/200 22/22 [==============================] - 52s 2s/step - loss: 0.0358 - accuracy: 0.7682 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 130/200 22/22 [==============================] - 52s 2s/step - loss: 0.0354 - accuracy: 0.7690 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 131/200 22/22 [==============================] - 52s 2s/step - loss: 0.0360 - accuracy: 0.7682 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 132/200 22/22 [==============================] - 52s 2s/step - loss: 0.0349 - accuracy: 0.7676 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 133/200 22/22 [==============================] - 53s 2s/step - loss: 0.0352 - accuracy: 0.7687 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 134/200 22/22 [==============================] - 52s 2s/step - loss: 0.0337 - accuracy: 0.7721 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 135/200 22/22 [==============================] - 53s 2s/step - loss: 0.0337 - accuracy: 0.7691 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 136/200 22/22 [==============================] - 52s 2s/step - loss: 0.0335 - accuracy: 0.7725 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 137/200 22/22 [==============================] - 53s 2s/step - loss: 0.0337 - accuracy: 0.7697 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 138/200 22/22 [==============================] - 54s 2s/step - loss: 0.0334 - accuracy: 0.7697 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 139/200 22/22 [==============================] - 54s 2s/step - loss: 0.0333 - accuracy: 0.7715 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 140/200 22/22 [==============================] - 53s 2s/step - loss: 0.0326 - accuracy: 0.7717 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 141/200 22/22 [==============================] - 53s 2s/step - loss: 0.0324 - accuracy: 0.7716 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 142/200 22/22 [==============================] - 52s 2s/step - loss: 0.0321 - accuracy: 0.7722 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 143/200 22/22 [==============================] - 53s 2s/step - loss: 0.0318 - accuracy: 0.7740 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 144/200 22/22 [==============================] - 53s 2s/step - loss: 0.0317 - accuracy: 0.7729 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 145/200 22/22 [==============================] - 54s 2s/step - loss: 0.0311 - accuracy: 0.7722 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 146/200 22/22 [==============================] - 53s 2s/step - loss: 0.0307 - accuracy: 0.7726 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 147/200 22/22 [==============================] - 53s 2s/step - loss: 0.0307 - accuracy: 0.7755 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 148/200 22/22 [==============================] - 53s 2s/step - loss: 0.0310 - accuracy: 0.7748 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 149/200 22/22 [==============================] - 53s 2s/step - loss: 0.0304 - accuracy: 0.7746 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 150/200 22/22 [==============================] - 52s 2s/step - loss: 0.0302 - accuracy: 0.7736 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 151/200 22/22 [==============================] - 53s 2s/step - loss: 0.0305 - accuracy: 0.7748 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 152/200 22/22 [==============================] - 53s 2s/step - loss: 0.0302 - accuracy: 0.7747 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 153/200 22/22 [==============================] - 53s 2s/step - loss: 0.0295 - accuracy: 0.7750 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 154/200 22/22 [==============================] - 53s 2s/step - loss: 0.0298 - accuracy: 0.7711 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 155/200 22/22 [==============================] - 53s 2s/step - loss: 0.0293 - accuracy: 0.7764 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 156/200 22/22 [==============================] - 53s 2s/step - loss: 0.0294 - accuracy: 0.7751 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 157/200 22/22 [==============================] - 53s 2s/step - loss: 0.0297 - accuracy: 0.7726 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 158/200 22/22 [==============================] - 53s 2s/step - loss: 0.0290 - accuracy: 0.7747 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 159/200 22/22 [==============================] - 52s 2s/step - loss: 0.0286 - accuracy: 0.7761 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 160/200 22/22 [==============================] - 53s 2s/step - loss: 0.0298 - accuracy: 0.7730 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 161/200 22/22 [==============================] - 54s 2s/step - loss: 0.0288 - accuracy: 0.7764 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 162/200 22/22 [==============================] - 53s 2s/step - loss: 0.0290 - accuracy: 0.7732 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 163/200 22/22 [==============================] - 54s 2s/step - loss: 0.0290 - accuracy: 0.7741 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 164/200 22/22 [==============================] - 54s 2s/step - loss: 0.0282 - accuracy: 0.7769 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 165/200 22/22 [==============================] - 53s 2s/step - loss: 0.0281 - accuracy: 0.7743 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 166/200 22/22 [==============================] - 54s 2s/step - loss: 0.0279 - accuracy: 0.7745 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 167/200 22/22 [==============================] - 53s 2s/step - loss: 0.0282 - accuracy: 0.7763 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 168/200 22/22 [==============================] - 53s 2s/step - loss: 0.0277 - accuracy: 0.7783 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 169/200 22/22 [==============================] - 53s 2s/step - loss: 0.0281 - accuracy: 0.7765 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 170/200 22/22 [==============================] - 53s 2s/step - loss: 0.0286 - accuracy: 0.7735 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 171/200 22/22 [==============================] - 53s 2s/step - loss: 0.0279 - accuracy: 0.7726 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 172/200 22/22 [==============================] - 53s 2s/step - loss: 0.0279 - accuracy: 0.7743 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 173/200 22/22 [==============================] - 54s 2s/step - loss: 0.0280 - accuracy: 0.7747 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 174/200 22/22 [==============================] - 53s 2s/step - loss: 0.0274 - accuracy: 0.7766 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 175/200 22/22 [==============================] - 53s 2s/step - loss: 0.0276 - accuracy: 0.7744 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 176/200 22/22 [==============================] - 53s 2s/step - loss: 0.0271 - accuracy: 0.7764 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 177/200 22/22 [==============================] - 53s 2s/step - loss: 0.0268 - accuracy: 0.7785 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 178/200 22/22 [==============================] - 53s 2s/step - loss: 0.0273 - accuracy: 0.7787 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 179/200 22/22 [==============================] - 53s 2s/step - loss: 0.0270 - accuracy: 0.7759 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 180/200 22/22 [==============================] - 53s 2s/step - loss: 0.0268 - accuracy: 0.7770 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 181/200 22/22 [==============================] - 53s 2s/step - loss: 0.0265 - accuracy: 0.7796 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 182/200 22/22 [==============================] - 53s 2s/step - loss: 0.0268 - accuracy: 0.7802 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 183/200 22/22 [==============================] - 53s 2s/step - loss: 0.0274 - accuracy: 0.7783 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 184/200 22/22 [==============================] - 53s 2s/step - loss: 0.0267 - accuracy: 0.7776 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 185/200 22/22 [==============================] - 53s 2s/step - loss: 0.0260 - accuracy: 0.7787 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 186/200 22/22 [==============================] - 53s 2s/step - loss: 0.0269 - accuracy: 0.7775 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 187/200 22/22 [==============================] - 53s 2s/step - loss: 0.0268 - accuracy: 0.7769 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 188/200 22/22 [==============================] - 53s 2s/step - loss: 0.0263 - accuracy: 0.7756 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 189/200 22/22 [==============================] - 53s 2s/step - loss: 0.0267 - accuracy: 0.7783 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 190/200 22/22 [==============================] - 53s 2s/step - loss: 0.0265 - accuracy: 0.7773 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 191/200 22/22 [==============================] - 52s 2s/step - loss: 0.0262 - accuracy: 0.7798 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 192/200 22/22 [==============================] - 53s 2s/step - loss: 0.0262 - accuracy: 0.7756 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 193/200 22/22 [==============================] - 53s 2s/step - loss: 0.0261 - accuracy: 0.7763 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 194/200 22/22 [==============================] - 53s 2s/step - loss: 0.0258 - accuracy: 0.7761 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 195/200 22/22 [==============================] - 53s 2s/step - loss: 0.0257 - accuracy: 0.7777 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 196/200 22/22 [==============================] - 52s 2s/step - loss: 0.0255 - accuracy: 0.7810 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 197/200 22/22 [==============================] - 52s 2s/step - loss: 0.0260 - accuracy: 0.7757 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 198/200 22/22 [==============================] - 52s 2s/step - loss: 0.0255 - accuracy: 0.7770 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 199/200 22/22 [==============================] - 53s 2s/step - loss: 0.0253 - accuracy: 0.7775 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Epoch 200/200 22/22 [==============================] - 53s 2s/step - loss: 0.0255 - accuracy: 0.7768 WARNING:tensorflow:Early stopping conditioned on metric val_loss which is not available. Available metrics are: loss,accuracy Done

Please wait while AnomalyDetector.h5 has been created Refresh when needed

参考链接:Crowd_Anomaly_Detection

0%