import tensorflow as tf
sys.path.insert(1, os.path.realpath(os.path.pardir))
import utils.kinetics_i3d_utils as ki3du
import i3d
# import skvideo
import utils.pre_process_rgb_flow as img_tool

#%%

gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)

tf_config = tf.ConfigProto()
# tf_config.gpu_options.per_process_gpu_memory_fraction = 0.99

eval_type = 'rgb'
cfg = ki3du.load_config(yml_path='run_config.yml')
ATTACK_CFG = cfg.SINGLE_VIDEO_ATTACK

kinetics_classes = ki3du.load_kinetics_classes(eval_type)

k_i3d = ki3du.kinetics_i3d(ckpt_path=cfg.MODEL.CKPT_PATH, batch_size=ATTACK_CFG.BATCH_SIZE)

if ATTACK_CFG.IMPROVE_ADV_LOSS:
    adversarial_loss = k_i3d.improve_adversarial_loss(margin=ATTACK_CFG.PROB_MARGIN,
                                                      targeted = ATTACK_CFG.TARGETED_ATTACK,
                                                      logits = ATTACK_CFG.USE_LOGITS)
else:
    adversarial_loss = k_i3d.ce_adversarial_loss(targeted=ATTACK_CFG.TARGETED_ATTACK)

beta_0_default = tf.constant(1, dtype=tf.float32)
beta_0 = tf.placeholder_with_default(beta_0_default, name='beta_0', shape=beta_0_default.shape)
Ejemplo n.º 2
0
        # dataset = dataset.batch(batch_size)
        dataset = dataset.prefetch(buffer_size=1)

        # images, labels = dataset.make_one_shot_iterator().get_next()
        #
        # features = {'images': images}
        return dataset

    return _input_fn


#%%
kinetics_classes = ki3du.load_kinetics_classes()

if sys.argv.__len__() > 1:
    cfg = ki3du.load_config(yml_path=sys.argv[1])
else:
    cfg = ki3du.load_config(yml_path='run_config.yml')

ATTACK_CFG = cfg.UNIVERSAL_ATTACK
source_class = ATTACK_CFG.TF_RECORDS_TRAIN_PATH[-1].split('/')[-2]
# assert source_class in kinetics_classes, "Oh no! {} not in kinetics classes".format(source_class)

# NUM_OF_VID_EACH_TF_RECORDS
# NUM_OF_TRAIN_TF_RECORDS
# NUM_OF_VAL_TF_RECORDS
if ATTACK_CFG.FLICKERING_ATTACK:
    attack_type = 'FLICKERING_ATTACK'
else:
    attack_type = 'SUP_ATTACK'