def create_model(dim): model = resnet18.make_resnet_18(dim).call(isTrain=False) model.trainable = False optimizer = tf.keras.optimizers.Adam(1e-4) return model, optimizer
def create_model(): # base_model=tf.keras.applications.InceptionV3( # include_top=False, # weights='imagenet', # input_tensor=None, # input_shape=[227,227,3], # pooling=None, # classes=2 # ) # # tf.keras.utils.plot_model(base_model , to_file='model_base.png', show_shapes=True, dpi=64) #Added to visualise model # base_model.trainable=False # model = tf.keras.Sequential() # model.add(base_model) # model.add(tf.keras.layers.Flatten()) # model.add(tf.keras.layers.Dense(2)) # model.add(tf.keras.layers.Softmax()) model = resnet18.make_resnet_18(dim).call(isTrain=False) model.trainable = False optimizer = tf.keras.optimizers.Adam(1e-4) return model, optimizer
train_summary_writer = tf.summary.create_file_writer(out_file) # out_file_Test = STORE_PATH + f"/TEST_{dt.datetime.now().strftime('%d%m%Y%H%M')}" # train_summary_writer_Test = tf.summary.create_file_writer(out_file_Test) train_dir1 = 'H:/Datasets/celebA_Male_female/669126_1178231_bundle_archive/Dataset/Train/Male' train_dir2 = 'H:/Datasets/celebA_Male_female/669126_1178231_bundle_archive/Dataset/Train/female' # images_concat_shuffled,images_labels_concat_shuffled=data.prep_dataset(train_dir1,train_dir2) images_labels_concat_shuffled, images_concat_shuffled = data.datasets( train_dir1, train_dir2, 13000, bias=0.5) # test_dir1 = 'H:/Datasets/celebA_Male_female/669126_1178231_bundle_archive/Dataset/Test/Male' # test_dir2 = 'H:/Datasets/celebA_Male_female/669126_1178231_bundle_archive/Dataset/Test/female' model = resnet18.make_resnet_18().call() tf.keras.utils.plot_model(model, to_file='resnet.png', show_shapes=True, dpi=64) #Added to visualise model optimizer = tf.keras.optimizers.Adam(1e-4) EPOCH = 10 BATCH_SIZE = 64 batch_num = len(images_labels_concat_shuffled) / BATCH_SIZE def cross_entropy_loss(expected_labels, predicted_labels): cross_entropy = tf.keras.losses.SparseCategoricalCrossentropy() loss = cross_entropy(expected_labels, predicted_labels)