Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(encoder): fix ffmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
Larryjianfeng committed Aug 7, 2019
2 parents fd37e6d + 909ec4b commit 82ee826
Show file tree
Hide file tree
Showing 19 changed files with 333 additions and 87 deletions.
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@

# Release Note (`v0.0.26`)
> Release time: 2019-08-02 18:18:45

🙇 We'd like to thank all contributors for this new release! In particular,
hanhxiao, Jem, Larry Yan, 🙇


### 🆕 New Features

- [[```d0b2ef0b```](https://github.com/gnes-ai/gnes/commit/d0b2ef0b1c8d781e558d1a7f0d7708c355f09d37)] __-__ __composer__: more interaction for gnes board (*hanhxiao*)
- [[```9c33dc66```](https://github.com/gnes-ai/gnes/commit/9c33dc66a2d1eb478138851ebb0fa27ebfcad9c5)] __-__ __router__: allow consecutive mapping and reducing ops (*hanhxiao*)

### 🐞 Bug fixes

- [[```fc5026da```](https://github.com/gnes-ai/gnes/commit/fc5026da1ee0021abfefcefaee2ec41c0583b2c2)] __-__ __board__: improve gnes board 500 message (*hanhxiao*)
- [[```823bdeda```](https://github.com/gnes-ai/gnes/commit/823bdeda9ead30ae989a8c46cb32a51581bc4753)] __-__ __test__: fix grpc gentle shutdown (*hanhxiao*)
- [[```f6a801f7```](https://github.com/gnes-ai/gnes/commit/f6a801f7b18a5df435335778deaba790df09526c)] __-__ __test__: fix preprocessor building for image test (*hanhxiao*)
- [[```50fdc041```](https://github.com/gnes-ai/gnes/commit/50fdc0414659d7fe0acf858fe23e67c1be1bee0b)] __-__ __base__: fix ref to CompositionalTrainableBase (*hanhxiao*)
- [[```54a931c7```](https://github.com/gnes-ai/gnes/commit/54a931c78345617014229792d9e9ac6ca6ae4f71)] __-__ __test__: fix test images by removing mac stuff (*hanhxiao*)
- [[```14cdfabe```](https://github.com/gnes-ai/gnes/commit/14cdfabed5bb1ac8e75f1944f31323c69df6d9d8)] __-__ __sliding window__: fix the boundary (*Jem*)
- [[```46b5c94e```](https://github.com/gnes-ai/gnes/commit/46b5c94eea4973e3f1b2dcb05e85981f316a4ca3)] __-__ __encoder__: fix name for video encoder (*Larry Yan*)
- [[```15eb50b4```](https://github.com/gnes-ai/gnes/commit/15eb50b4d1a85e3b3ddd8ceeb7e3fd0b2b45b428)] __-__ __encoder__: fix params in basevideo encoder (*Larry Yan*)
- [[```5b0fe7c6```](https://github.com/gnes-ai/gnes/commit/5b0fe7c6c3c5f2fa433c090fdad9c8c80d59f4df)] __-__ __preprocessor__: fix FFmpegVideoSegmentor (*Larry Yan*)
- [[```d6a46fa6```](https://github.com/gnes-ai/gnes/commit/d6a46fa6b6a931b4dc0e334f5a89bb66460a84b0)] __-__ __encoder__: fix import path for mixture encoder (*Larry Yan*)
- [[```17779676```](https://github.com/gnes-ai/gnes/commit/17779676bd452b2679ba7e64918721cf85e0bec1)] __-__ __encoder__: fix mixture encoder (*Larry Yan*)
- [[```95f03c56```](https://github.com/gnes-ai/gnes/commit/95f03c56701f4a691f8412490f6dcf9565751da1)] __-__ __encoder__: fix bug in video mixture encoder (*Larry Yan*)
- [[```3fdf1c06```](https://github.com/gnes-ai/gnes/commit/3fdf1c06e302a5c3e32d28de431e076802ff5c9e)] __-__ __encoder__: fix mixture (*Larry Yan*)
- [[```67991533```](https://github.com/gnes-ai/gnes/commit/679915336a2d3d99041844717723e8a06dae5899)] __-__ __encoder__: add netvlad and netfv register class (*Larry Yan*)
- [[```92500f0f```](https://github.com/gnes-ai/gnes/commit/92500f0f1451914a7c68efdd71158b8cd03103c1)] __-__ __encoder__: add netvlad and netfv (*Larry Yan*)

### 🚧 Code Refactoring

- [[```c430ef64```](https://github.com/gnes-ai/gnes/commit/c430ef64eaa6960a9768b006c1959630ae4f18d4)] __-__ __base__: better batch_size control (*hanhxiao*)
- [[```58217d8c```](https://github.com/gnes-ai/gnes/commit/58217d8cd3deaad6dbca6e8683e5baeea370593f)] __-__ __base__: moving is_trained to class attribute (*hanhxiao*)
- [[```7126d496```](https://github.com/gnes-ai/gnes/commit/7126d496e1195c7469e417672329145e326d5c1c)] __-__ __preprocessor__: separate resize logic from the unary preprocessor (*hanhxiao*)
- [[```52f87c7f```](https://github.com/gnes-ai/gnes/commit/52f87c7fa2d54b25a6b075cf549ce960ed63b59d)] __-__ __base__: make pipelineencoder more general and allow pipelinepreprocessor (*hanhxiao*)

### 📗 Documentation

- [[```3ab3723e```](https://github.com/gnes-ai/gnes/commit/3ab3723e9f1fc9b095ad6d7a808330d47d28f2c6)] __-__ __tutorial__: fix image and code layout (*hanhxiao*)

### 🍹 Other Improvements

- [[```635ba37f```](https://github.com/gnes-ai/gnes/commit/635ba37f6970bb0c2d5cb3919df673d0327a9593)] __-__ __changelog__: update change log to v0.0.25 (*hanhxiao*)

# Release Note (`v0.0.25`)
> Release time: 2019-07-26 19:45:21
Expand Down
2 changes: 1 addition & 1 deletion gnes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

# do not change this line
# this is managed by git tag and replaced on every release
__version__ = '0.0.25'
__version__ = '0.0.26'
43 changes: 24 additions & 19 deletions gnes/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@
import argparse


def resolve_yaml_path(path):
# priority, filepath > classname > default
import os
import io
if hasattr(path, 'read'):
# already a readable stream
return path
elif os.path.exists(path):
return open(path, encoding='utf8')
elif path.isidentifier():
# possible class name
return io.StringIO('!%s {}' % path)
elif path.startswith('!'):
# possible YAML content
return io.StringIO(path)
else:
raise argparse.ArgumentTypeError('%s can not be resolved, it should be a readable stream,'
' or a valid file path, or a supported class name.' % path)


def set_base_parser():
from .. import __version__
from termcolor import colored
Expand Down Expand Up @@ -49,7 +69,7 @@ def set_composer_parser(parser=None):
type=str,
default='GNES app',
help='name of the instance')
parser.add_argument('--yaml_path', type=argparse.FileType('r'),
parser.add_argument('--yaml_path', type=resolve_yaml_path,
default=resource_stream(
'gnes', '/'.join(('resources', 'config', 'compose', 'default.yml'))),
help='yaml config of the service')
Expand Down Expand Up @@ -134,14 +154,12 @@ def _set_client_parser(parser=None):
def set_loadable_service_parser(parser=None):
if not parser:
parser = set_base_parser()
from pkg_resources import resource_stream
from ..service.base import SocketType
set_service_parser(parser)

parser.add_argument('--yaml_path', type=argparse.FileType('r'),
default=resource_stream(
'gnes', '/'.join(('resources', 'config', 'encoder', 'default.yml'))),
help='yaml config of the service')
parser.add_argument('--yaml_path', type=resolve_yaml_path, required=True,
help='yaml config of the service, it should be a readable stream,'
' or a valid file path, or a supported class name.')

parser.set_defaults(socket_in=SocketType.PULL_BIND,
socket_out=SocketType.PUSH_BIND)
Expand All @@ -151,39 +169,26 @@ def set_loadable_service_parser(parser=None):
def set_preprocessor_service_parser(parser=None):
if not parser:
parser = set_base_parser()
from pkg_resources import resource_stream
set_loadable_service_parser(parser)
parser.get_default('yaml_path').close()
parser.set_defaults(yaml_path=resource_stream(
'gnes', '/'.join(('resources', 'config', 'preprocessor', 'default.yml'))))

parser.set_defaults(read_only=True)
return parser


def set_router_service_parser(parser=None):
from pkg_resources import resource_stream
if not parser:
parser = set_base_parser()
set_loadable_service_parser(parser)
parser.get_default('yaml_path').close()
parser.set_defaults(yaml_path=resource_stream(
'gnes', '/'.join(('resources', 'config', 'router', 'default.yml'))))

parser.set_defaults(read_only=True)
return parser


def set_indexer_service_parser(parser=None):
from ..service.base import SocketType
from pkg_resources import resource_stream

if not parser:
parser = set_base_parser()
set_loadable_service_parser(parser)
parser.get_default('yaml_path').close()
parser.set_defaults(yaml_path=resource_stream(
'gnes', '/'.join(('resources', 'config', 'indexer', 'default.yml'))))

# encoder's port_out is indexer's port_in
parser.set_defaults(port_in=parser.get_default('port_out'),
Expand Down
84 changes: 36 additions & 48 deletions gnes/composer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class YamlComposer:
}

comp2args = {
'Encoder': set_loadable_service_parser().parse_args([]),
'Router': set_router_service_parser().parse_args([]),
'Indexer': set_indexer_service_parser().parse_args([]),
'Encoder': set_loadable_service_parser().parse_args(['--yaml_path', 'BaseEncoder']),
'Router': set_router_service_parser().parse_args(['--yaml_path', 'BaseRouter']),
'Indexer': set_indexer_service_parser().parse_args(['--yaml_path', 'BaseIndexer']),
'gRPCFrontend': set_grpc_frontend_parser().parse_args([]),
'Preprocessor': set_preprocessor_service_parser().parse_args([])
'Preprocessor': set_preprocessor_service_parser().parse_args(['--yaml_path', 'BasePreprocessor'])
}

class Layer:
Expand Down Expand Up @@ -188,20 +188,23 @@ def build_dockerswarm(all_layers: List['YamlComposer.Layer'], docker_img: str =
args = ['--%s %s' % (a, str(v) if ' ' not in str(v) else ('"%s"' % str(v))) for a, v in c.items() if
a in YamlComposer.comp2args[c['name']] and a != 'yaml_path' and v]
if 'yaml_path' in c and c['yaml_path'] is not None:
args.append('--yaml_path /%s_yaml' % c_name)
config_dict['%s_yaml' % c_name] = {'file': c['yaml_path']}

# if l_idx + 1 < len(all_layers):
# next_layer = all_layers[l_idx + 1]
# _l_idx = l_idx + 1
# else:
# next_layer = all_layers[0]
# _l_idx = 0
# host_out_name = ''
# for _c_idx, _c in enumerate(next_layer.components):
# if _c['port_in'] == c['port_out']:
# host_out_name = '%s%d%d' % (_c['name'], _l_idx, _c_idx)
# break
if c['yaml_path'].endswith('.yml') or c['yaml_path'].endswith('.yaml'):
args.append('--yaml_path /%s_yaml' % c_name)
config_dict['%s_yaml' % c_name] = {'file': c['yaml_path']}
else:
args.append('--yaml_path %s' % c['yaml_path'])

if l_idx + 1 < len(all_layers):
next_layer = all_layers[l_idx + 1]
_l_idx = l_idx + 1
else:
next_layer = all_layers[0]
_l_idx = 0
host_out_name = ''
for _c_idx, _c in enumerate(next_layer.components):
if _c['port_in'] == c['port_out']:
host_out_name = '%s%d%d' % (_c['name'], _l_idx, _c_idx)
break

if l_idx - 1 >= 0:
last_layer = all_layers[l_idx - 1]
Expand All @@ -216,8 +219,10 @@ def build_dockerswarm(all_layers: List['YamlComposer.Layer'], docker_img: str =
host_in_name = '%s%d%d' % (_c['name'], _l_idx, _c_idx)
break

args += ['--host_in %s' % host_in_name]
# '--host_out %s' % host_out_name]
if 'BIND' not in c['socket_out']:
args.append('--host_out %s' % host_out_name)
if 'BIND' not in c['socket_in']:
args.append('--host_in %s' % host_in_name)

cmd = '%s %s' % (YamlComposer.comp2file[c['name']], ' '.join(args))
swarm_lines['services'][c_name] = CommentedMap({
Expand All @@ -235,7 +240,8 @@ def build_dockerswarm(all_layers: List['YamlComposer.Layer'], docker_img: str =
}
})

if 'yaml_path' in c and c['yaml_path'] is not None:
if 'yaml_path' in c and c['yaml_path'] is not None \
and (c['yaml_path'].endswith('.yml') or c['yaml_path'].endswith('.yaml')):
swarm_lines['services'][c_name]['configs'] = ['%s_yaml' % c_name]

if c['name'] == 'gRPCFrontend':
Expand Down Expand Up @@ -382,7 +388,7 @@ def rule3():
self._num_layer += 1
last_layer.components[0]['socket_out'] = str(SocketType.PUSH_CONNECT)
r = CommentedMap({'name': 'Router',
'yaml_path': None,
'yaml_path': 'BaseRouter',
'socket_in': str(SocketType.PULL_BIND),
'socket_out': str(SocketType.PUSH_BIND),
'port_in': last_layer.components[0]['port_out'],
Expand All @@ -403,6 +409,8 @@ def rule5():
# a shortcut fn: based on c3(): (N)-2-(N) with pub sub connection
rule3()
router_layers[0].components[0]['socket_out'] = str(SocketType.PUB_BIND)
router_layers[0].components[0]['yaml_path'] = '"!PublishRouter {parameter: {num_part: %d}}"' \
% len(layer.components)
for c in layer.components:
c['socket_in'] = str(SocketType.SUB_CONNECT)

Expand All @@ -413,7 +421,7 @@ def rule6():
for c in layer.components:
income = self.Layer.get_value(c, 'income')
r = CommentedMap({'name': 'Router',
'yaml_path': None,
'yaml_path': 'BaseReduceRouter',
'socket_in': str(SocketType.SUB_CONNECT),
'socket_out': str(SocketType.PUSH_BIND) if income == 'pull' else str(
SocketType.PUB_BIND),
Expand All @@ -430,7 +438,7 @@ def rule7():
router_layer = YamlComposer.Layer(layer_id=self._num_layer)
self._num_layer += 1
r0 = CommentedMap({'name': 'Router',
'yaml_path': None,
'yaml_path': '"!PublishRouter {parameter: {num_part: %d}}"' % len(layer.components),
'socket_in': str(SocketType.PULL_BIND),
'socket_out': str(SocketType.PUB_BIND),
'port_in': self._get_random_port(),
Expand All @@ -443,7 +451,7 @@ def rule7():
self._num_layer += 1
for c in layer.components:
r = CommentedMap({'name': 'Router',
'yaml_path': None,
'yaml_path': 'BaseRouter',
'socket_in': str(SocketType.SUB_CONNECT),
'socket_out': str(SocketType.PUSH_BIND),
'port_in': r0['port_out'],
Expand All @@ -459,7 +467,7 @@ def rule10():
router_layer = YamlComposer.Layer(layer_id=self._num_layer)
self._num_layer += 1
r0 = CommentedMap({'name': 'Router',
'yaml_path': None,
'yaml_path': '"!PublishRouter {parameter: {num_part: %d}}"' % len(layer.components),
'socket_in': str(SocketType.PULL_BIND),
'socket_out': str(SocketType.PUB_BIND),
'port_in': self._get_random_port(),
Expand All @@ -476,7 +484,7 @@ def rule8():
router_layer = YamlComposer.Layer(layer_id=self._num_layer)
self._num_layer += 1
r = CommentedMap({'name': 'Router',
'yaml_path': None,
'yaml_path': 'BaseReduceRouter',
'socket_in': str(SocketType.PULL_BIND),
'socket_out': str(SocketType.PUSH_BIND),
'port_in': self._get_random_port(),
Expand All @@ -487,7 +495,7 @@ def rule8():
if last_income == 'sub':
c['socket_out'] = str(SocketType.PUSH_CONNECT)
r_c = CommentedMap({'name': 'Router',
'yaml_path': None,
'yaml_path': 'BaseReduceRouter',
'socket_in': str(SocketType.PULL_BIND),
'socket_out': str(SocketType.PUSH_CONNECT),
'port_in': self._get_random_port(),
Expand Down Expand Up @@ -517,26 +525,6 @@ def rule9():
last_layer.components[0]['socket_out'] = str(SocketType.PUSH_CONNECT)
layer.components[0]['socket_in'] = str(SocketType.PULL_BIND)

def rule11():
# a shortcut fn: (N)-2-(N) with push pull connection
router_layer = YamlComposer.Layer(layer_id=self._num_layer)
self._num_layer += 1
r = CommentedMap({'name': 'Router',
'yaml_path': None,
'socket_in': str(SocketType.PULL_BIND),
'socket_out': str(SocketType.PUSH_BIND),
'port_in': self._get_random_port(),
'port_out': self._get_random_port()})

for c in last_layer.components:
c['socket_out'] = str(SocketType.PUSH_CONNECT)
c['port_out'] = r['port_in']
for c in layer.components:
c['socket_in'] = str(SocketType.PULL_CONNECT)
c['port_in'] = r['port_out']
router_layer.append(r)
router_layers.append(router_layer)

router_layers = [] # type: List['self.Layer']
# bind the last out to current in

Expand Down
4 changes: 2 additions & 2 deletions gnes/encoder/image/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ def _encode(_, img: List['np.ndarray']):
# for video
if len(img[0].shape) == 4:
padding_image, max_lenth = _padding(img)
output = _encode(None, padding_image)
output = _encode(self, padding_image)
# for image
else:
output = _encode(None, img)
output = _encode(self, img)

return output
2 changes: 1 addition & 1 deletion gnes/encoder/image/inception.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ def _encode(_, data):
feed_dict={self.inputs: data})
return end_points_[self.select_layer]

return _encode(None, img).astype(np.float32)
return _encode(self, img).astype(np.float32)
Loading

0 comments on commit 82ee826

Please sign in to comment.