Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def after_training_test_pred(self, dos='C:\\Users\\maxim\\random_data\\4 trackmania A04\\', size=(160,120), nimg_size=(5,5), sleeptime=1):
Dataset = dataset.Dataset([dataset.direction_component, dataset.speed_component, dataset.time_component])
for i in Dataset.load_dos(dos):
img = cv2.imread(i)
if self.load_speed:
speed = Dataset.load_component_item(i, 1)
pred_img(self, img, size, sleeptime, speed=speed, nimg_size=nimg_size)
from tf_conversions import posemath as pm
from geometry_msgs.msg import Pose, Quaternion
LOGGER = logging.getLogger(__name__)
try:
import rospy, rosbag
except ImportError, e:
LOGGER.warning("Could not load rospy/rosbag for TOM dataset." \
"Original error: %s" % str(e))
'''
Load a set of ROS bags
'''
class TomDataset(Dataset):
right_arm_end_frame_topic = "/tom/arm_right/Xef_w"
gripper_topic = "/tom/arm_right/hand/gripperState"
arm_data_topic = "/tom/arm_right/RobotData"
vision_topic = "/tom/head/vision/manager/visual_info"
skin_topic = "/tom/arm_right/hand/semanticGripperCells"
FOLDER = 0
GOOD = 1
# set up the folders to read from
folders = [
("Ilya_Box", True),
("Ilya_Trash", False),
("Karinne_Box", True),
("Karinne_Trash", False),
def gen_data(num_items):
index = np.arange(num_items)
dataset = Dataset(index=index, batch_class=ArrayBatch)
return dataset
if args.no_augmentation:
augmentation = lambda x: x
else:
augmentation = processing.build_anp_augmentation_module(
saturation=args.saturation,
brightness_contrast=args.brightness_contrast,
gaus_blur_prob=args.gaus_blur_prob,
gaus_blur_size=args.gaus_blur_size,
gaus_blur_sigma=args.gaus_blur_sigma
).cuda()
if args.targeted:
dataset = Dataset(args.input_dir)
else:
dataset = Dataset(args.input_dir, target_file='')
attack = CWInspired(
target_model,
augmentation,
max_epsilon=args.max_epsilon,
n_iter=args.n_iter,
lr=args.lr,
targeted=args.targeted,
target_nth_highest=args.target_nth_highest,
prob_dont_augment=0.0,
always_target=args.always_target,
random_start=args.random_start,
n_restarts = args.n_restarts
)
runner = ImageSaveAttackRunner(dataset, args.output_dir, time_limit_per_100=args.time_limit_per_100)
def load_dataset(dataset_spec=None, verbose=True, **spec_overrides):
if verbose: print('Loading dataset...')
if dataset_spec is None: dataset_spec = config.dataset
dataset_spec = dict(dataset_spec) # take a copy of the dict before modifying it
dataset_spec.update(spec_overrides)
dataset_spec['h5_path'] = os.path.join(config.data_dir, dataset_spec['h5_path'])
if 'label_path' in dataset_spec: dataset_spec['label_path'] = os.path.join(config.data_dir, dataset_spec['label_path'])
training_set = dataset.Dataset(**dataset_spec)
#
#print("****************************************")
#print("原有shape:",training_set.shape)
#测试,直接交换两个维度,看效果
#training_set=np.swapaxes(training_set,1,2)
#training_set=np.swapaxes(training_set,2,3)
#print("变换后shape:",training_set.shape)
#
if verbose: print('Dataset shape =', np.int32(training_set.shape).tolist())
drange_orig = training_set.get_dynamic_range()
if verbose: print('Dynamic range =', drange_orig)
return training_set, drange_orig
model = getattr(base, FLAGS.model)(embedding)
logging.info(model)
train = melt.apps.get_train()
init_fn = None
# TODO FIXME should like below but now has problem
# File "/home/gezi/mine/wenzheng/utils/melt/util.py", line 38, in create_restore_fn
# assert variables_to_restore, tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES)
# AssertionError: [, , , , , , , , , , , ]
# if FLAGS.lm_path:
# init_fn = melt.create_restore_fn(FLAGS.lm_path, FLAGS.model, 'TextEncoder')
train(Dataset,
model,
criterion,
eval_fn=ev.evaluate,
init_fn=init_fn,
valid_write_fn=ev.valid_write,
infer_write_fn=ev.infer_write,
valid_suffix='.valid.csv',
infer_suffix='.infer.csv')
parent_path = os.path.join('models_src', 'OSVOS_parent', 'OSVOS_parent.ckpt-50000')
logs_path = os.path.join('models_src', seq_name, label_id)
if train_model:
max_training_iters = int(sys.argv[2])
# Define Dataset
test_frames = sorted(os.listdir(os.path.join(baseDir, 'DAVIS', 'JPEGImages', '480p', seq_name)))
test_imgs = [os.path.join(baseDir, 'DAVIS', 'JPEGImages', '480p', seq_name, frame) for frame in test_frames]
if train_model:
train_imgs = [os.path.join(baseDir, 'DAVIS', 'JPEGImages', '480p', seq_name, '00000.jpg')+' '+
os.path.join(baseDir, 'DAVIS', 'Annotations', '480p_split', seq_name, label_id, '00000.png')]
print train_imgs
print label_id
dataset = Dataset(train_imgs, test_imgs, './', data_aug=True, data_aug_scales=[0.5, 0.8, 1])
else:
dataset = Dataset(None, test_imgs, './')
# Train the network
if train_model:
# More training parameters
learning_rate = 1e-3
save_step = max_training_iters
side_supervision = 3
display_step = 10
with tf.Graph().as_default():
with tf.device('/gpu:' + str(gpu_id)):
global_step = tf.Variable(0, name='global_step', trainable=False)
osvos.train_finetune(dataset, parent_path, side_supervision, learning_rate, logs_path, max_training_iters,
save_step, display_step, global_step, iter_mean_grad=1, instance_norm=True, ckpt_name=seq_name)
# Test the network
with tf.Graph().as_default():
with tf.device('/gpu:' + str(gpu_id)):
def prepare(args):
"""
checks data, creates the directories, prepare the vocabulary and embeddings
"""
logger = logging.getLogger("brc")
logger.info('Checking the data files...')
for data_path in args.train_files + args.dev_files + args.test_files:
assert os.path.exists(data_path), '{} file does not exist.'.format(data_path)
logger.info('Preparing the directories...')
for dir_path in [args.vocab_dir, args.model_dir, args.result_dir, args.summary_dir]:
if not os.path.exists(dir_path):
os.makedirs(dir_path)
logger.info('Building vocabulary...')
brc_data = Dataset(args.max_p_num, args.max_p_len, args.max_q_len, args.max_w_len,
args.train_files, args.dev_files, args.test_files)
vocab = Vocab(lower=True)
for word in brc_data.word_iter('train'):
vocab.add(word)
for word in brc_data.word_iter('dev'):
vocab.add(word)
for word in brc_data.word_iter('test'):
vocab.add(word)
logger.info('Assigning embeddings...')
vocab.load_pretrained_char_embeddings(args.char_embed)
vocab.load_pretrained_word_embeddings(args.word_embed)
vocab.randomly_init_embeddings(args.pos_embed_dim)
logger.info('Saving vocab...')
with open(os.path.join(args.vocab_dir, 'vocab.data'), 'wb') as fout:
u, s, _ = pca(data)
#u, s, _ = pca(data)
#import pdb
#pdb.set_trace()
number_of_vectors = pca_variance_threshold(s, percent_variance=percent_variance)
return np.matrix(u[:,0:number_of_vectors+1])
def randomized_vectors(dataset, number_of_vectors):
rvectors = np.matrix(np.random.random_sample((dataset.num_attributes(), number_of_vectors))) * 2 - 1.0
lengths = np.diag(1.0 / np.power(np.sum(np.power(rvectors, 2), axis=0), 0.5))
return rvectors * lengths
##
# Dataset which performs linear dimensionality reduction
class LinearDimReduceDataset(ds.Dataset):
def __init__(self, inputs, outputs):
ds.Dataset.__init__(self, inputs, outputs)
self.original_inputs = inputs
##
# Project this dataset's input instances (stores original instances)
def reduce_input(self):
self.original_inputs = self.inputs
self.inputs = self.projection_basis.T * self.inputs
##
# Projection vectors are assumed to be column vectors
def set_projection_vectors(self, vec):
self.projection_basis = vec
def train_model(self, nr_of_files=-1):
self.logger.println("train model called")
start_time = timeit.default_timer()
cs = CrfSuite()
dataset = Dataset()
data = dataset.read(nr_of_files=nr_of_files)
nr_of_filled_lines, data1 = dataset.filter_for_filled_tags(data)
data2 = dataset.obtain_default_tags(nr_of_filled_lines*3, data)
data = data1 + data2
data = dataset.shuffle_data(data)
train_set, test_set = dataset.split_dataset(data)
we_model = WeModel()
w2v_model = we_model.train(data) # optionally load a pretrained model here
we_model.save(w2v_model)
we_model = None
word2count, word2idx = dataset.encode_dataset(train_set)
f_generator = FeatureGenerator(w2v_model, word2count, word2idx)
w2v_model = None