第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

使用 TensorFlow-Keras API 進(jìn)行數(shù)據(jù)增強(qiáng)

使用 TensorFlow-Keras API 進(jìn)行數(shù)據(jù)增強(qiáng)

躍然一笑 2023-08-22 14:55:47
以下代碼允許訓(xùn)練集的圖像在每個(gè)時(shí)期結(jié)束時(shí)旋轉(zhuǎn) 90°。from skimage.io import imreadfrom skimage.transform import resize, rotateimport numpy as npimport tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import layersfrom keras.utils import Sequence from keras.models import Sequentialfrom keras.layers import Conv2D, Activation, Flatten, Dense# Model architecture  (dummy)model = Sequential()model.add(Conv2D(32, (3, 3), input_shape=(15, 15, 4)))model.add(Activation('relu'))model.add(Flatten())modl.add(Dense(1))model.add(Activation('sigmoid'))model.compile(loss='binary_crossentropy',              optimizer='rmsprop',              metrics=['accuracy'])# Data iterator class CIFAR10Sequence(Sequence):    def __init__(self, filenames, labels, batch_size):        self.filenames, self.labels = filenames, labels        self.batch_size = batch_size        self.angles = [0,90,180,270]        self.current_angle_idx = 0    # Method to loop throught the available angles    def change_angle(self):      self.current_angle_idx += 1      if self.current_angle_idx >= len(self.angles):        self.current_angle_idx = 0      def __len__(self):        return int(np.ceil(len(self.filenames) / float(self.batch_size)))    # read, resize and rotate the image and return a batch of images    def __getitem__(self, idx):        angle = self.angles[self.current_angle_idx]        print (f"Rotating Angle: {angle}")        batch_x = self.filenames[idx * self.batch_size:(idx + 1) * self.batch_size]        batch_y = self.labels[idx * self.batch_size:(idx + 1) * self.batch_size]        return np.array([            rotate(resize(imread(filename), (15, 15)), angle)               for filename in batch_x]), np.array(batch_y)如何修改代碼以便在每個(gè)紀(jì)元期間發(fā)生圖像的旋轉(zhuǎn)?換句話說(shuō),我如何編寫(xiě)一個(gè)在紀(jì)元“結(jié)束”時(shí)運(yùn)行的回調(diào),該回調(diào)會(huì)更改角度值并繼續(xù)在同一紀(jì)元上進(jìn)行訓(xùn)練(而不更改到下一個(gè)紀(jì)元)?
查看完整描述

2 回答

?
慕尼黑8549860

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊

由于您有一個(gè)自定義序列生成器,您可以創(chuàng)建一個(gè)在紀(jì)元開(kāi)始或結(jié)束時(shí)運(yùn)行的函數(shù)。您可以在其中放置代碼來(lái)修改圖像。文檔位于[此處。][1]


Epoch-level methods (training only)

on_epoch_begin(self, epoch, logs=None)

Called at the beginning of an epoch during training.


on_epoch_end(self, epoch, logs=None)

Called at the end of an epoch during training.



  [1]: https://keras.io/guides/writing_your_own_callbacks/


查看完整回答
反對(duì) 回復(fù) 2023-08-22
?
UYOU

TA貢獻(xiàn)1878條經(jīng)驗(yàn) 獲得超4個(gè)贊

沒(méi)有必要CustomCallback為此目的創(chuàng)建一個(gè);最后,您希望在訓(xùn)練期間進(jìn)行增強(qiáng)。


解決方案是應(yīng)用旋轉(zhuǎn)操作的概率


# read, resize and rotate the image and return a batch of images

def __getitem__(self, idx):

    angle = self.angles[self.current_angle_idx]

    print(f"Rotating Angle: {angle}")

    batch_x = self.filenames[idx * self.batch_size:(idx + 1) * self.batch_size]

    batch_y = self.labels[idx * self.batch_size:(idx + 1) * self.batch_size]

    #These new lines (say we augment with probability > 0.5)

    #Number between 0 and 1

    images = []

    for filename in batch_x:

        probability = random.random()

        apply_rotate = probability > 0.5

        if apply_rotate:

            images.append(rotate(resize(imread(filename), (15, 15)), angle))

        else:

            images.append(resize(imread(filename), (15, 15)))

    return np.array(images), np.array(batch_y)


查看完整回答
反對(duì) 回復(fù) 2023-08-22
  • 2 回答
  • 0 關(guān)注
  • 1649 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)