本文整理汇总了Python中vgg19.VGG19属性的典型用法代码示例。如果您正苦于以下问题:Python vgg19.VGG19属性的具体用法?Python vgg19.VGG19怎么用?Python vgg19.VGG19使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类vgg19
的用法示例。
在下文中一共展示了vgg19.VGG19属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_vgg19
# 需要导入模块: import vgg19 [as 别名]
# 或者: from vgg19 import VGG19 [as 别名]
def build_vgg19(self, x, reuse=None):
with tf.variable_scope("vgg19", reuse=reuse):
# image re-scaling
x = tf.cast((x + 1) / 2, dtype=tf.float32) # [-1, 1] to [0, 1]
x = tf.cast(x * 255., dtype=tf.float32) # [0, 1] to [0, 255]
r, g, b = tf.split(x, 3, 3)
bgr = tf.concat([b - self.vgg_mean[0],
g - self.vgg_mean[1],
r - self.vgg_mean[2]], axis=3)
self.vgg19 = vgg19.VGG19(bgr)
net = self.vgg19.vgg19_net['conv5_4']
return net # last layer
示例2: build_fcn
# 需要导入模块: import vgg19 [as 别名]
# 或者: from vgg19 import VGG19 [as 别名]
def build_fcn(self):
vgg19_net = vgg19.VGG19(image=self.x)
net = vgg19_net.vgg19_net['pool5']
net = t.conv2d(net, 4096, k=7, s=1, name='conv6_1')
net = tf.nn.relu(net, name='relu6_1')
net = tf.nn.dropout(net, self.do_rate, name='dropout-6_1')
net = t.conv2d(net, 4096, k=1, s=1, name='conv7_1')
net = tf.nn.relu(net, name='relu7_1')
net = tf.nn.dropout(net, self.do_rate, name='dropout-7_1')
feature = t.conv2d(net, self.n_classes, k=1, s=1, name='conv8_1')
net = t.deconv2d(feature, vgg19_net.vgg19_net['pool4'].get_shape()[3], name='deconv_1')
net = tf.add(net, vgg19_net.vgg19_net['pool4'], name='fuse_1')
示例3: compute_VGG19_features
# 需要导入模块: import vgg19 [as 别名]
# 或者: from vgg19 import VGG19 [as 别名]
def compute_VGG19_features(keras_model_path, size, batch_size=32):
sys.path.append(keras_model_path)
from vgg19 import VGG19
from imagenet_utils import preprocess_input
from keras.models import Model
# Load data
hdf5_file = os.path.join(data_dir, "lfw_%s_data.h5" % size)
with h5py.File(hdf5_file, "a") as hf:
X = hf["data"][:].astype(np.float32)
X = preprocess_input(X)
base_model = VGG19(weights='imagenet', include_top=False)
list_output = ["block3_conv1", "block4_conv1", "block5_conv1"]
list_output = [base_model.get_layer(l).output for l in list_output]
model = Model(input=base_model.input, output=list_output)
vgg19_feat = model.predict(X, batch_size=batch_size, verbose=True)
for i in range(len(vgg19_feat)):
hf.create_dataset("data_VGG_%s" % str(i), data=vgg19_feat[i])
示例4: parse_args
# 需要导入模块: import vgg19 [as 别名]
# 或者: from vgg19 import VGG19 [as 别名]
def parse_args():
desc = "Tensorflow implementation of 'Image Style Transfer Using Convolutional Neural Networks"
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('--vgg_model', type=str, default='pre_trained_model', help='The directory where the pre-trained model was saved', required=True)
parser.add_argument('--trainDB_path', type=str, default='train2014',
help='The directory where MSCOCO DB was saved', required=True)
parser.add_argument('--style', type=str, default='style/wave.jpg', help='File path of style image (notation in the paper : a)', required=True)
parser.add_argument('--output', type=str, default='models', help='File path for trained-model. Train-log is also saved here.', required=True)
parser.add_argument('--content_weight', type=float, default=7.5e0, help='Weight of content-loss')
parser.add_argument('--style_weight', type=float, default=5e2, help='Weight of style-loss')
parser.add_argument('--tv_weight', type=float, default=2e2, help='Weight of total-variance-loss')
parser.add_argument('--content_layers', nargs='+', type=str, default=['relu4_2'], help='VGG19 layers used for content loss')
parser.add_argument('--style_layers', nargs='+', type=str, default=['relu1_1', 'relu2_1', 'relu3_1', 'relu4_1', 'relu5_1'],
help='VGG19 layers used for style loss')
parser.add_argument('--content_layer_weights', nargs='+', type=float, default=[1.0], help='Content loss for each content is multiplied by corresponding weight')
parser.add_argument('--style_layer_weights', nargs='+', type=float, default=[.2,.2,.2,.2,.2],
help='Style loss for each content is multiplied by corresponding weight')
parser.add_argument('--learn_rate', type=float, default=1e-3, help='Learning rate for Adam optimizer')
parser.add_argument('--num_epochs', type=int, default=2, help='The number of epochs to run')
parser.add_argument('--batch_size', type=int, default=4, help='Batch size')
parser.add_argument('--checkpoint_every', type=int, default=1000, help='save a trained model every after this number of iterations')
parser.add_argument('--test', type=str, default=None,
help='File path of content image (notation in the paper : x)')
parser.add_argument('--max_size', type=int, default=None, help='The maximum width or height of input images')
return check_args(parser.parse_args())
示例5: build_vgg19
# 需要导入模块: import vgg19 [as 别名]
# 或者: from vgg19 import VGG19 [as 别名]
def build_vgg19(self, x, reuse=None):
with tf.variable_scope("vgg19", reuse=reuse):
# image re-scaling
x = tf.cast((x + 1) / 2, dtype=tf.float32) # [-1, 1] to [0, 1]
x = tf.cast(x * 255., dtype=tf.float32) # [0, 1] to [0, 255]
r, g, b = tf.split(x, 3, 3)
bgr = tf.concat([b - self.vgg_mean[0],
g - self.vgg_mean[1],
r - self.vgg_mean[2]], axis=3)
self.vgg19 = vgg19.VGG19(bgr)
net = self.vgg19.vgg19_net['conv3_3']
return net
示例6: main
# 需要导入模块: import vgg19 [as 别名]
# 或者: from vgg19 import VGG19 [as 别名]
def main():
# parse arguments
args = parse_args()
if args is None:
exit()
# initiate VGG19 model
model_file_path = args.vgg_model + '/' + vgg19.MODEL_FILE_NAME
vgg_net = vgg19.VGG19(model_file_path)
# get file list for training
content_images = utils.get_files(args.trainDB_path)
# load style image
style_image = utils.load_image(args.style)
# create a map for content layers info
CONTENT_LAYERS = {}
for layer, weight in zip(args.content_layers,args.content_layer_weights):
CONTENT_LAYERS[layer] = weight
# create a map for style layers info
STYLE_LAYERS = {}
for layer, weight in zip(args.style_layers, args.style_layer_weights):
STYLE_LAYERS[layer] = weight
# open session
sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True))
# build the graph for train
trainer = style_transfer_trainer.StyleTransferTrainer(session=sess,
content_layer_ids=CONTENT_LAYERS,
style_layer_ids=STYLE_LAYERS,
content_images=content_images,
style_image=add_one_dim(style_image),
net=vgg_net,
num_epochs=args.num_epochs,
batch_size=args.batch_size,
content_weight=args.content_weight,
style_weight=args.style_weight,
tv_weight=args.tv_weight,
learn_rate=args.learn_rate,
save_path=args.output,
check_period=args.checkpoint_every,
test_image=args.test,
max_size=args.max_size,
)
# launch the graph in a session
trainer.train()
# close session
sess.close()