MCPcopy Create free account
hub / github.com/10Ring/LAA-Net / extract_endpoints

Method extract_endpoints

models/networks/pose_efficientNet.py:409–454  ·  view source on GitHub ↗

Use convolution layer to extract features from reduction levels i in [1, 2, 3, 4, 5]. Args: inputs (tensor): Input tensor. Returns: Dictionary of last intermediate features with reduction levels i in [1, 2, 3, 4, 5]. Example:

(self, inputs)

Source from the content-addressed store, hash-verified

407 block.set_swish(memory_efficient)
408
409 def extract_endpoints(self, inputs):
410 """Use convolution layer to extract features
411 from reduction levels i in [1, 2, 3, 4, 5].
412 Args:
413 inputs (tensor): Input tensor.
414 Returns:
415 Dictionary of last intermediate features
416 with reduction levels i in [1, 2, 3, 4, 5].
417 Example:
418 >>> import torch
419 >>> from efficientnet.model import EfficientNet
420 >>> inputs = torch.rand(1, 3, 224, 224)
421 >>> model = EfficientNet.from_pretrained('efficientnet-b0')
422 >>> endpoints = model.extract_endpoints(inputs)
423 >>> print(endpoints['reduction_1'].shape) # torch.Size([1, 16, 112, 112])
424 >>> print(endpoints['reduction_2'].shape) # torch.Size([1, 24, 56, 56])
425 >>> print(endpoints['reduction_3'].shape) # torch.Size([1, 40, 28, 28])
426 >>> print(endpoints['reduction_4'].shape) # torch.Size([1, 112, 14, 14])
427 >>> print(endpoints['reduction_5'].shape) # torch.Size([1, 320, 7, 7])
428 >>> print(endpoints['reduction_6'].shape) # torch.Size([1, 1280, 7, 7])
429 """
430 endpoints = dict()
431
432 # Stem
433 x = self._swish(self._bn0(self._conv_stem(inputs)))
434 prev_x = x
435
436 # Blocks
437 for idx, block in enumerate(self._blocks):
438 drop_connect_rate = self._global_params.drop_connect_rate
439 if drop_connect_rate:
440 drop_connect_rate *= float(idx) / len(self._blocks) # scale drop connect_rate
441 x = block(x, drop_connect_rate=drop_connect_rate)
442 # print('Prev', prev_x.size())
443 # print('X', x.size())
444 if prev_x.size(2) > x.size(2):
445 endpoints['reduction_{}'.format(len(endpoints) + 1)] = prev_x
446 elif idx == len(self._blocks) - 1:
447 endpoints['reduction_{}'.format(len(endpoints) + 1)] = x
448 prev_x = x
449
450 # Head
451 x = self._swish(self._bn1(self._conv_head(x)))
452 endpoints['reduction_{}'.format(len(endpoints) + 1)] = x
453
454 return endpoints
455
456 def extract_features(self, inputs):
457 """use convolution layer to extract feature .

Callers 1

forwardMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected