def get_optuna_conext(cls, training_name: str, trial: Trial) -> Context: """トライアルの開始準備をする。Objective関数の最初に呼び出してください。 Parameters: trial : 開始するトライアルオブジェクト """ print("get_context", trial) cls.trial = trial context = Context.init_context(training_name) context[Context.OPTUNA] = True context[Context.OPTUNA_TRIAL] = trial return context
def pretext_dataset(dataset:tf.data.Dataset, start_label:int)->tf.data.Dataset: filtered = dataset.filter(lambda data:data['label'] >= start_label) def supervised_transform(data): image = data['image'] image = tf.cast(image, tf.float32) image = image / 255.0 def random_transform(image): pass if __name__ == '__main__': context = Context.init_context(TRAINING_NAME='') # ENABLE_SUSPEND_RESUME_TRAINING() BATCH_SIZE = 500 CLASS_NUM = 10 IMAGE_SIZE = 28 EPOCHS = 2 SHUFFLE_SIZE = 1000 # if IS_SUSPEND_RESUME_TRAIN() == True and IS_ON_COLABOLATORY_WITH_GOOGLE_DRIVE()== True:
from tftk.image.dataset import Mnist from tftk.image.dataset import ImageDatasetUtil from tftk.image.model.classification import SimpleClassificationModel from tftk.callback import CallbackBuilder from tftk.optimizer import OptimizerBuilder from tftk import Context from tftk.train.image import ImageTrain from tftk import ENABLE_SUSPEND_RESUME_TRAIN, IS_SUSPEND_RESUME_TRAIN, ResumeExecutor if __name__ == '__main__': context = Context.init_context( TRAINING_NAME="20200519141141") # .TRAINING_NAME:}) ENABLE_SUSPEND_RESUME_TRAIN() BATCH_SIZE = 500 CLASS_NUM = 10 IMAGE_SIZE = 28 EPOCHS = 20 SHUFFLE_SIZE = 1000 train, train_len = Mnist.get_train_dataset() validation, validation_len = Mnist.get_test_dataset() train = train.map(ImageDatasetUtil.image_reguralization()).map( ImageDatasetUtil.one_hot(CLASS_NUM)) validation = validation.map(ImageDatasetUtil.image_reguralization()).map( ImageDatasetUtil.one_hot(CLASS_NUM)) optimizer = OptimizerBuilder.get_optimizer(name="rmsprop") model = SimpleClassificationModel.get_model(input_shape=(IMAGE_SIZE,
from tftk.image.dataset import Mnist from tftk.image.dataset import ImageDatasetUtil from tftk.image.model.classification import SimpleClassificationModel from tftk.callback import CallbackBuilder from tftk.optimizer import OptimizerBuilder from tftk import Context from tftk.train.image import ImageTrain from tftk import ENABLE_SUSPEND_RESUME_TRAINING, ResumeExecutor if __name__ == '__main__': context = Context.init_context(TRAINING_NAME='mnist_y') # ENABLE_SUSPEND_RESUME_TRAINING() BATCH_SIZE = 500 CLASS_NUM = 10 IMAGE_SIZE = 28 EPOCHS = 2 SHUFFLE_SIZE = 1000 # if IS_SUSPEND_RESUME_TRAIN() == True and IS_ON_COLABOLATORY_WITH_GOOGLE_DRIVE()== True: train, train_len = Mnist.get_train_dataset() validation, validation_len = Mnist.get_test_dataset() train = train.map(ImageDatasetUtil.image_reguralization()).map( ImageDatasetUtil.one_hot(CLASS_NUM)) validation = validation.map(ImageDatasetUtil.image_reguralization()).map( ImageDatasetUtil.one_hot(CLASS_NUM))
from tftk.image.dataset import Mnist from tftk.image.dataset import ImageDatasetUtil from tftk.image.model.classification import SimpleClassificationModel from tftk.callback import CallbackBuilder from tftk.optimizer import OptimizerBuilder from tftk import Context from tftk.train.image import ImageTrain from tftk import ENABLE_SUSPEND_RESUME_TRAIN, IS_SUSPEND_RESUME_TRAIN, ResumeExecutor if __name__ == '__main__': context = Context.init_context( TRAINING_BASE_DIR="tmp", TRAINING_NAME="resume_test" ) ENABLE_SUSPEND_RESUME_TRAIN() BATCH_SIZE = 500 CLASS_NUM = 10 IMAGE_SIZE = 28 EPOCHS = 3 SHUFFLE_SIZE = 1000 BASEDIR = "./tmp" TRAIN_NAME = "resume_test" # if IS_SUSPEND_RESUME_TRAIN() == True and IS_ON_COLABOLATORY_WITH_GOOGLE_DRIVE()== True:
import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' import tftk from tftk.image.dataset import Food1o1 from tftk.image.dataset import ImageDatasetUtil from tftk.image.model import KerasResNet50V2 from tftk.train.image import ImageTrain from tftk.image.augument import ImageAugument from tftk.callback import CallbackBuilder from tftk.optimizer import OptimizerBuilder from tftk import Context if __name__ == '__main__': context = Context.init_context(TRAINING_BASE_DIR="tmp", TRAINING_NAME="food101") tftk.USE_MIXED_PRECISION() BATCH_SIZE = 64 CLASS_NUM = 101 IMAGE_SIZE = 224 CHANNELS = 3 EPOCHS = 100 SHUFFLE_SIZE = 1000 train, train_len = Food1o1.get_train_dataset() validation, validation_len = Food1o1.get_validation_dataset() train = train.map(ImageDatasetUtil.resize_with_crop_or_pad( IMAGE_SIZE, IMAGE_SIZE),
from tftk.image.model import SimpleClassificationModel from tftk.train.image import ImageTrain from tftk.callback import CallbackBuilder from tftk.optimizer import OptimizerBuilder if __name__ == '__main__': CLASS_NUM = 10 IMAGE_SIZE = 150 IMAGE_CHANNELS = 3 EPOCHS = 100 BATCH_SIZE = 100 tftk.ENABLE_MIXED_PRECISION() context = Context.init_context(TRAINING_NAME='DogsVsCats') train, train_len = ImageLabelFolderDataset.get_train_dataset( name="dogs-vs-cats", manual_dir="tmp") validation, validation_len = ImageLabelFolderDataset.get_validation_dataset( name="dogs-vs-cats", manual_dir="tmp") train = train.map(ImageDatasetUtil.map_max_square_crop_and_resize( IMAGE_SIZE, IMAGE_SIZE), num_parallel_calls=tf.data.experimental.AUTOTUNE) train = train.map(ImageAugument.randaugment_map(2, 4), num_parallel_calls=tf.data.experimental.AUTOTUNE) train = train.map(ImageDatasetUtil.image_reguralization(), num_parallel_calls=tf.data.experimental.AUTOTUNE) train = train.map(ImageDatasetUtil.one_hot(CLASS_NUM), num_parallel_calls=tf.data.experimental.AUTOTUNE)