def update_lambda_every_meta(ori, up, hyper_lr, updatemode): tmp = [] for x, y in zip(ori, up): if updatemode == 'unit': new_y = np.mean(y, axis=1, keepdims=True) tmp.append(x.get_value() - np.sign(new_y) * np.array(float(hyper_lr) * 1., dtype=theano.config.floatX)) print("metaupdate", x.get_value()[0][1], tmp[-1][0][1]) else: raise AttributeError return tmp if __name__ == '__main__': args = setup() print('all argument: ', args) temp_lambda = None loss_change = [] tmp_weights = None for i in range(args.metaEpoch): # Michael: update_lambda = temp_lambda, fix_weight = tmp_weights in run_exp origin_lambda, temp_lambda, tmp_weights, eval_loss, eval_err = run_exp(args, temp_lambda, tmp_weights) temp_lambda = update_lambda_every_meta(origin_lambda, temp_lambda, args.lrHyper, 'unit') loss_change.append((float(eval_loss), eval_err)) print("---------------------------------------------------------------------------------------------------") print("Training Result: ") for k, v in enumerate(loss_change): print(k, v) print("---------------------------------------------------------------------------------------------------")
import cv2 import os import args import imageio import numpy from PIL import Image arguments = args.setup() videoSource = arguments.video requestedResolution = int(arguments.resolution) if requestedResolution < 1 or requestedResolution > 3: raise Exception('Requested resolution is not in the acceptable range') videoDestinationPath = arguments.out if __name__ == '__main__': if videoSource == '': raise Exception('requested frame is longer than video.') if not os.path.isfile(videoSource): raise Exception('video not found.') video = cv2.VideoCapture(videoSource) videoLength = int(video.get(cv2.CAP_PROP_FRAME_COUNT) ) #returns the total number of frames in video videoFrameWidth = video.get( cv2.CAP_PROP_FRAME_WIDTH) #returns the width size of frames in video videoFrameHeight = video.get( cv2.CAP_PROP_FRAME_HEIGHT) #returns the height size of frames in video