def load_fet_extractor( deployfile_relpath, weights_relpath, image_dims=(256, 256), mean=(104, 117, 123), device_id=0, input_scale=1, ): add_caffe_to_path() import caffe FeatureExtractor = def_FeatureExtractor(caffe) mean = np.array(mean) model_file = os.path.join(settings.CAFFE_ROOT, deployfile_relpath) pretrained_file = os.path.join(settings.CAFFE_ROOT, weights_relpath) if settings.CAFFE_GPU: print 'Using GPU' caffe.set_mode_gpu() print 'Using device #{}'.format(device_id) caffe.set_device(device_id) else: print 'Using CPU' caffe.set_mode_cpu() net = FeatureExtractor( model_file=model_file, pretrained_file=pretrained_file, image_dims=image_dims, mean=mean, input_scale=input_scale, raw_scale=255, channel_swap=(2, 1, 0), ) return caffe, net
def import_caffe(): import utils utils.add_caffe_to_path() import caffe return caffe