Python nets.vgg.vgg_arg_scope() Examples
The following are 6
code examples of nets.vgg.vgg_arg_scope().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
nets.vgg
, or try the search function
.
Example #1
Source File: model_train.py From ICDAR-2019-SROIE with MIT License | 6 votes |
def model(image): image = mean_image_subtraction(image) with slim.arg_scope(vgg.vgg_arg_scope()): conv5_3 = vgg.vgg_16(image) rpn_conv = slim.conv2d(conv5_3, 512, 3) lstm_output = Bilstm(rpn_conv, 512, 128, 512, scope_name='BiLSTM') bbox_pred = lstm_fc(lstm_output, 512, 10 * 4, scope_name="bbox_pred") cls_pred = lstm_fc(lstm_output, 512, 10 * 2, scope_name="cls_pred") # transpose: (1, H, W, A x d) -> (1, H, WxA, d) cls_pred_shape = tf.shape(cls_pred) cls_pred_reshape = tf.reshape(cls_pred, [cls_pred_shape[0], cls_pred_shape[1], -1, 2]) cls_pred_reshape_shape = tf.shape(cls_pred_reshape) cls_prob = tf.reshape(tf.nn.softmax(tf.reshape(cls_pred_reshape, [-1, cls_pred_reshape_shape[3]])), [-1, cls_pred_reshape_shape[1], cls_pred_reshape_shape[2], cls_pred_reshape_shape[3]], name="cls_prob") return bbox_pred, cls_pred, cls_prob
Example #2
Source File: model_train.py From ctpn-crnn with MIT License | 6 votes |
def model(image): image = mean_image_subtraction(image) with slim.arg_scope(vgg.vgg_arg_scope()): conv5_3 = vgg.vgg_16(image) rpn_conv = slim.conv2d(conv5_3, 512, 3) lstm_output = Bilstm(rpn_conv, 512, 128, 512, scope_name='BiLSTM') bbox_pred = lstm_fc(lstm_output, 512, 10 * 4, scope_name="bbox_pred") cls_pred = lstm_fc(lstm_output, 512, 10 * 2, scope_name="cls_pred") # transpose: (1, H, W, A x d) -> (1, H, WxA, d) cls_pred_shape = tf.shape(cls_pred) cls_pred_reshape = tf.reshape(cls_pred, [cls_pred_shape[0], cls_pred_shape[1], -1, 2]) cls_pred_reshape_shape = tf.shape(cls_pred_reshape) cls_prob = tf.reshape(tf.nn.softmax(tf.reshape(cls_pred_reshape, [-1, cls_pred_reshape_shape[3]])), [-1, cls_pred_reshape_shape[1], cls_pred_reshape_shape[2], cls_pred_reshape_shape[3]], name="cls_prob") return bbox_pred, cls_pred, cls_prob
Example #3
Source File: faster_rcnn_vgg_16_feature_extractor.py From mtl-ssl with Apache License 2.0 | 6 votes |
def _extract_proposal_features(self, preprocessed_inputs, scope): if len(preprocessed_inputs.get_shape().as_list()) != 4: raise ValueError('`preprocessed_inputs` must be 4 dimensional, got a ' 'tensor of shape %s' % preprocessed_inputs.get_shape()) shape_assert = tf.Assert( tf.logical_and( tf.greater_equal(tf.shape(preprocessed_inputs)[1], 33), tf.greater_equal(tf.shape(preprocessed_inputs)[2], 33)), ['image size must at least be 33 in both height and width.']) with tf.control_dependencies([shape_assert]): with slim.arg_scope( vgg.vgg_arg_scope(weight_decay=self._weight_decay)): with tf.variable_scope( self._architecture, reuse=self._reuse_weights) as var_scope: _, endpoints = self._vgg_model( preprocessed_inputs, final_endpoint='conv5', trainable=self._is_training, freeze_layer=self._freeze_layer, scope=var_scope) handle = self._base_features return endpoints[handle]
Example #4
Source File: attack_vgg16_mim.py From Translation-Invariant-Attacks with Apache License 2.0 | 5 votes |
def graph(x, y, i, x_max, x_min, grad): eps = FLAGS.max_epsilon num_iter = FLAGS.num_iter alpha = eps / num_iter momentum = FLAGS.momentum num_classes = 1000 with slim.arg_scope(vgg.vgg_arg_scope()): logits, end_points = vgg.vgg_16( x, num_classes=num_classes, is_training=False) pred = tf.argmax(logits, 1) first_round = tf.cast(tf.equal(i, 0), tf.int64) y = first_round * pred + (1 - first_round) * y one_hot = tf.one_hot(y, num_classes) cross_entropy = tf.losses.softmax_cross_entropy(one_hot, logits, label_smoothing=0.0, weights=1.0) noise = tf.gradients(cross_entropy, x)[0] noise = tf.nn.depthwise_conv2d(noise, stack_kernel, strides=[1, 1, 1, 1], padding='SAME') noise = noise / tf.reduce_mean(tf.abs(noise), [1,2,3], keep_dims=True) noise = momentum * grad + noise x = x + alpha * tf.sign(noise) x = tf.clip_by_value(x, x_min, x_max) i = tf.add(i, 1) return x, y, i, x_max, x_min, noise
Example #5
Source File: pretrained.py From SSD_tensorflow_VOC with Apache License 2.0 | 5 votes |
def use_vgg16(self): with tf.Graph().as_default(): image_size = vgg.vgg_16.default_image_size img_path = "../../data/misec_images/First_Student_IC_school_bus_202076.jpg" checkpoint_path = "../../data/trained_models/vgg16/vgg_16.ckpt" image_string = tf.read_file(img_path) image = tf.image.decode_jpeg(image_string, channels=3) processed_image = vgg_preprocessing.preprocess_image(image, image_size, image_size, is_training=False) processed_images = tf.expand_dims(processed_image, 0) # Create the model, use the default arg scope to configure the batch norm parameters. with slim.arg_scope(vgg.vgg_arg_scope()): # 1000 classes instead of 1001. logits, _ = vgg.vgg_16(processed_images, num_classes=1000, is_training=False) probabilities = tf.nn.softmax(logits) init_fn = slim.assign_from_checkpoint_fn( checkpoint_path, slim.get_model_variables('vgg_16')) with tf.Session() as sess: init_fn(sess) np_image, probabilities = sess.run([image, probabilities]) probabilities = probabilities[0, 0:] sorted_inds = [i[0] for i in sorted(enumerate(-probabilities), key=lambda x:x[1])] self.disp_names(sorted_inds,probabilities,include_background=False) plt.figure() plt.imshow(np_image.astype(np.uint8)) plt.axis('off') plt.title(img_path) plt.show() return
Example #6
Source File: faster_rcnn_vgg_16_feature_extractor.py From mtl-ssl with Apache License 2.0 | 5 votes |
def _extract_box_classifier_features(self, proposal_feature_maps, scope): with tf.variable_scope(self._architecture, reuse=self._reuse_weights): with slim.arg_scope( vgg.vgg_arg_scope(weight_decay=self._weight_decay)): proposal_classifier_features = tf.identity(proposal_feature_maps) return proposal_classifier_features