簡體   English   中英

為什么 epoch 2 花費的時間是 epoch 1 的 18 倍?

[英]Why does epoch 2 take 18 times more time than epoch 1?

我在 keras 中有以下神經網絡(對它的審查可能沒有必要回答我的問題:

簡短摘要:這是一個神經網絡,將圖像作為輸入並輸出圖像。 神經網絡主要是卷積的。 我使用發電機。 另外,我有兩個回調:一個用於 TensorBoard,另一個用於保存檢查點

class modelsClass(object):
    def __init__(self, img_rows = 272, img_cols = 480):

        self.img_rows = img_rows
        self.img_cols = img_cols

    def addPadding(self, layer, level): #height, width, level):

        w1, h1 = self.img_cols, self.img_rows
        w2, h2 = int(w1/2), int(h1/2)
        w3, h3 = int(w2/2), int(h2/2)
        w4, h4 = int(w3/2), int(h3/2)
        h = [h1, h2, h3, h4]
        w = [w1, w2, w3, w4]

        # Target width and height
        tw = w[level-1]
        th = h[level-1]

        # Source width and height
        lsize = keras.int_shape(layer)
        sh = lsize[1]
        sw = lsize[2]

        pw = (0, tw - sw)
        ph = (0, th - sh)

        layer = ZeroPadding2D(padding=(ph, pw), data_format="channels_last")(layer)

        return layer

[我需要在這里用一些文字打破代碼來發布問題]

    def getmodel(self):

        input_blurred = Input((self.img_rows, self.img_cols,3))

        conv1 = Conv2D(64, (3, 3), activation='relu', padding='same')(input_blurred)
        conv1 = Conv2D(64, (3, 3), activation='relu', padding='same')(conv1)
        pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)

        conv2 = Conv2D(128, (3, 3), activation='relu', padding='same')(pool1)
        conv2 = Conv2D(128, (3, 3), activation='relu', padding='same')(conv2)
        pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)

        conv3 = Conv2D(256, (3, 3), activation='relu', padding='same')(pool2)
        conv3 = Conv2D(256, (3, 3), activation='relu', padding='same')(conv3)
        pool3 = MaxPooling2D(pool_size=(2, 2))(conv3)

        conv4 = Conv2D(512, (3, 3), activation='relu', padding='same')(pool3)
        conv4 = Conv2D(512, (3, 3), activation='relu', padding='same')(conv4)
        pool4 = MaxPooling2D(pool_size=(2, 2))(conv4)

        conv5 = Conv2D(1024, (3, 3), activation='relu', padding='same')(pool4)
        conv5 = Conv2D(1024, (3, 3), activation='relu', padding='same')(conv5)

        up6 = Conv2DTranspose(512, (2, 2), strides=(2, 2), padding='same')(conv5)
        up6 = self.addPadding(up6,level=4)
        up6 = concatenate([up6,conv4], axis=3)
        conv6 = Conv2D(512, (3, 3), activation='relu', padding='same')(up6)
        conv6 = Conv2D(512, (3, 3), activation='relu', padding='same')(conv6)

        up7 = Conv2DTranspose(256, (2, 2), strides=(2, 2), padding='same')(conv6)
        up7 = self.addPadding(up7,level=3)
        up7 = concatenate([up7,conv3], axis=3)
        conv7 = Conv2D(256, (3, 3), activation='relu', padding='same')(up7)
        conv7 = Conv2D(256, (3, 3), activation='relu', padding='same')(conv7)

        up8 = Conv2DTranspose(128, (2, 2), strides=(2, 2), padding='same')(conv7)
        up8 = self.addPadding(up8,level=2)
        up8 = concatenate([up8,conv2], axis=3)
        conv8 = Conv2D(128, (3, 3), activation='relu', padding='same')(up8)
        conv8 = Conv2D(128, (3, 3), activation='relu', padding='same')(conv8)

        up9 = Conv2DTranspose(64, (2, 2), strides=(2, 2), padding='same')(conv8)
        up9 = self.addPadding(up9,level=1)
        up9 = concatenate([up9,conv1], axis=3)
        conv9 = Conv2D(64, (3, 3), activation='relu', padding='same')(up9)
        conv9 = Conv2D(64, (3, 3), activation='relu', padding='same')(conv9)

        conv10 = Conv2D(3, (1, 1), activation='linear')(conv9)

        model = Model(inputs=input_blurred, outputs=conv10)

        return model

然后代碼是:

models = modelsClass(720, 1280)
model = models.getmodel()

model.compile(optimizer='adam', loss='mean_absolute_error')
model_checkpoint = ModelCheckpoint('checkpoints/cp.ckpt', monitor='val_loss', verbose=0, save_best_only=False, save_weights_only=False, mode='auto', save_freq='epoch')
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir='some_dir', histogram_freq=1)
model_history = model.fit_generator(generator_train, epochs=3,
                          steps_per_epoch=900,
                          callbacks=[tensorboard_callback, model_checkpoint],
                          validation_data=generator_val, validation_steps=100)

其中generator_train.__len__ = 900generator_val.__len__ = 100 ,兩者的批量大小 = 1。
epoch 1 的時間為 10 分鍾,epoch 2 的時間為 3 小時。 我想知道可能是什么問題

以下是一些可以降低程序速度的一般事項:

  • 另一個程序使用的 CPU/GPU
  • 內存交換:您的計算機將內容從 RAM 移動到磁盤,因為 RAM 不足。 這可能是因為在您的腳本中,您試圖將所有內容都保存在內存中(例如之前輸出的列表,甚至可能帶有它們的漸變),或者因為另一個程序也開始使用大量 RAM。
  • 計算機發熱(可能在第一個紀元之后變熱了)
  • 省電(如果是筆記本電腦並且您拔掉了電源,則可能)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM