total_examples = len(dataset) total_batches = total_examples // batch_size model = build_model(ishape=ishape, mode='train', net_name=net_name) # model.summary() # model.load_weights('{}/weights_.h5'.format(output_path), by_name=True) min_loss = 2**32 for epoch in range(total_epoches): # tf.keras.backend.set_value(model.optimizer.learning_rate, 0.001) gen = genxy(dataset=dataset, image_dir_path=image_dir_path, ishape=ishape, total_batches=total_batches, batch_size=batch_size) print('\nTrain epoch {}'.format(epoch)) loss = np.zeros(total_batches) for batch in range(total_batches): batchx4d, batchy4d = next(gen) batch_loss = model.train_on_batch(batchx4d, batchy4d) loss[batch] = batch_loss print('-', end='') if batch % 100 == 99: print('{:.2f}%'.format((batch + 1) * 100 / total_batches), end='\n')
# model.load_weights('{}/weights_.h5'.format(output_path), by_name=True) min_loss = 2**32 max_precision = 0 max_recall = 0 train_dataset = load_dataset(anno_file_path=train_anno_file_path) test_dataset = load_dataset(anno_file_path=test_anno_file_path) for epoch in range(total_epoches): # tf.keras.backend.set_value(model.optimizer.learning_rate, 0.001) gen = genxy(dataset=train_dataset, image_dir=train_image_dir, ishape=ishape, abox_2dtensor=abox_2dtensor, iou_thresholds=iou_thresholds, total_examples=total_train_examples, total_classes=total_classes, anchor_sampling=anchor_sampling) print('\nTrain epoch {}'.format(epoch)) loss = np.zeros(total_train_examples) for batch in range(total_train_examples): batchx_4dtensor, batchy_2dtensor, _ = next(gen) batch_loss = model.train_on_batch(batchx_4dtensor, batchy_2dtensor) loss[batch] = batch_loss print('-', end='') if batch % 100 == 99: print('{:.2f}%'.format((batch + 1) * 100 / total_train_examples),
abox_2dtensor = tf.reshape(tensor=abox_4dtensor, shape=[-1, 4]) model = build_model(ishape=ishape, resnet_settings=resnet_settings, k=len(asizes), total_classes=total_classes) # model.summary() # model.load_weights('{}/weights.h5'.format(output_path), by_name=True) min_loss = 2**32 max_precision = 0 max_recall = 0 for epoch in range(total_epoches): gen = genxy( anno_file_path=train_anno_file_path, image_dir=train_image_dir, ishape=ishape, abox_2dtensor=abox_2dtensor, iou_thresholds=iou_thresholds, total_classes=total_classes, anchor_sampling=anchor_sampling, mode='train') print('\nTrain epoch {}'.format(epoch)) loss = np.zeros(total_train_examples) for batch in range(total_train_examples): batchx_4dtensor, batchy_2dtensor, _, _ = next(gen) batch_loss = model.train_on_batch(batchx_4dtensor, batchy_2dtensor) loss[batch] = batch_loss if batch%10==9: print('-', end='')
asizes=asizes[2]), dtype='float32') # (h3*w3*k3, 4) a4box_2dtensor = tf.constant(value=genanchors(isize=ishape[:2], ssize=ssizes[3], asizes=asizes[3]), dtype='float32') # (h4*w4*k4, 4) abox_2dtensors = [ a1box_2dtensor, a2box_2dtensor, a3box_2dtensor, a4box_2dtensor ] abox_2dtensor = tf.concat(values=abox_2dtensors, axis=0) dataset = load_dataset(anno_file_path=anno_file_path) gen = genxy(dataset=dataset, image_dir=image_dir, ishape=ishape, abox_2dtensors=abox_2dtensors, iou_thresholds=iou_thresholds, total_examples=total_examples, total_classes=total_classes, anchor_samplings=anchor_samplings) for _ in range(total_examples): print('{}: 1'.format(datetime.now().time()), end='\n') batchx_4dtensor, batchy_2dtensor, bboxes = next(gen) print('{}: 2'.format(datetime.now().time()), end='\n') pix = batchx_4dtensor[0] clz_2dtensor = batchy_2dtensor[:, :total_classes + 1] # (h*w*k, total_classes+1) sum_clz_2dtensor = tf.math.reduce_sum(input_tensor=clz_2dtensor, axis=-1) # (h*w*k,)