Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unstructured Sedna Lifelong Learning Architecture #392

Merged
merged 4 commits into from
Mar 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add base class for all the algorithm modules of unstructured lifelong…
… learning

Signed-off-by: SiqiLuo <1587295470@qq.com>
  • Loading branch information
luosiqi committed Mar 30, 2023

Verified

This commit was signed with the committer’s verified signature.
mssola Miquel Sabaté Solà
commit 5dce8ff69ef57765f5ac763dab584c5f0c0fb391
Original file line number Diff line number Diff line change
@@ -39,8 +39,6 @@ def preprocess_url(image_urls):

sample = {'image': _img, 'depth': _depth, 'label': _img}
composed_transforms = transforms.Compose([
# tr.CropBlackArea(),
# tr.FixedResize(size=self.args.crop_size),
tr.Normalize(
mean=(
0.485, 0.456, 0.406), std=(
11 changes: 11 additions & 0 deletions examples/lifelong_learning/robot_dog_delivery/RFNet/evaluate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import os
os.environ["TEST_DATASET_URL"] = "/home/lsq/RFNet/data_index/test.txt"
os.environ["MODEL_URLS"] = "s3://kubeedge/sedna-robo/kb/index.pkl"
os.environ["OUTPUT_URL"] = "s3://kubeedge/sedna-robo/kb_next/"

os.environ["KB_SERVER"] = "http://0.0.0.0:9020"
os.environ["operator"] = "<"
os.environ["model_threshold"] = "0.01"

os.environ["S3_ENDPOINT_URL"] = "https://obs.cn-north-1.myhuaweicloud.com"
os.environ["SECRET_ACCESS_KEY"] = "OYPxi4uD9k5E90z0Od3Ug99symbJZ0AfyB4oveQc"
os.environ["ACCESS_KEY_ID"] = "EMPTKHQUGPO2CDUFD2YR"

from sedna.core.lifelong_learning import LifelongLearning
from sedna.datasources import TxtDataParse
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Integrate the inference results of all related tasks
"""

from typing import List

import numpy as np

from ..artifact import Task


class BaseInferenceIntegrate:
"""
Base class for default calculation algorithm for inference integration

Parameters
----------
models: All models used for sample inference
"""

def __init__(self, models: list, **kwargs):
self.models = models

def __call__(self, tasks: List[Task]):
"""
Parameters
----------
tasks: All tasks with sample result

Returns
-------
result: inference results for all the inference samples
"""
raise NotImplementedError
Original file line number Diff line number Diff line change
@@ -22,13 +22,14 @@

from sedna.common.class_factory import ClassFactory, ClassType

from .base_inference_integrate import BaseInferenceIntegrate
from ..artifact import Task

__all__ = ('DefaultInferenceIntegrate', )


@ClassFactory.register(ClassType.STP)
class DefaultInferenceIntegrate:
class DefaultInferenceIntegrate(BaseInferenceIntegrate):
"""
Default calculation algorithm for inference integration

@@ -38,7 +39,7 @@ class DefaultInferenceIntegrate:
"""

def __init__(self, models: list, **kwargs):
self.models = models
super(DefaultInferenceIntegrate, self).__init__(models)

def __call__(self, tasks: List[Task]):
"""

This file was deleted.

5 changes: 0 additions & 5 deletions lib/sedna/algorithms/seen_task_learning/seen_task_learning.py
Original file line number Diff line number Diff line change
@@ -460,11 +460,6 @@ def predict(self, data: BaseDataSource,
if post_process:
callback = ClassFactory.get_cls(ClassType.CALLBACK, post_process)()

res = kwargs.get("prediction")
tasks = kwargs.get("tasks")
if res and tasks:
return res, tasks

tasks = []
for inx, df in enumerate(samples):
m = models[inx]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Mining tasks of inference sample base on task attribute extractor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base on -> based on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


Parameters
----------
samples : infer sample, see `sedna.datasources.BaseDataSource` for more detail.

Returns
-------
allocations : tasks that assigned to each sample
"""

from sedna.datasources import BaseDataSource


class BaseTaskAllocation:
"""
Base class of task allocation algorithm

Parameters
----------
task_extractor : Model or dict
task extractor is used to predict target tasks
"""

def __init__(self, task_extractor, **kwargs):
self.task_extractor = task_extractor

def __call__(self, samples: BaseDataSource):
raise NotImplementedError
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
from sedna.datasources import BaseDataSource
from sedna.common.class_factory import ClassFactory, ClassType

from .base_task_allocation import BaseTaskAllocation

@ClassFactory.register(ClassType.STP)
class TaskAllocationByOrigin:
class TaskAllocationByOrigin(BaseTaskAllocation):
"""
Corresponding to `TaskDefinitionByOrigin`

Parameters
----------
task_extractor : Dict
used to match target tasks
used to predict target tasks for each inference samples
origins: List[Metadata]
metadata is usually a class feature
label with a finite values.
"""

def __init__(self, task_extractor, **kwargs):
self.task_extractor = task_extractor
super(TaskAllocationByOrigin, self).__init__(task_extractor)
self.default_origin = kwargs.get("default", None)

def __call__(self, samples: BaseDataSource):

This file was deleted.

Original file line number Diff line number Diff line change
@@ -2,23 +2,24 @@
from sedna.datasources import BaseDataSource
from sedna.common.class_factory import ClassFactory, ClassType

from .base_task_allocation import BaseTaskAllocation

@ClassFactory.register(ClassType.STP)
class TaskAllocationSimple:
class TaskAllocationSimple(BaseTaskAllocation):
"""
Corresponding to `TaskDefinitionByOrigin`

Parameters
----------
task_extractor : Dict
used to match target tasks
used to predict target tasks for each inference sample
origins: List[Metadata]
metadata is usually a class feature
label with a finite values.
"""

def __init__(self, task_extractor, **kwargs):
self.task_extractor = task_extractor
super(TaskAllocationSimple, self).__init__(task_extractor)

def __call__(self, samples: BaseDataSource):
allocations = np.zeros(samples.num_examples(), dtype=np.int8)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Divide multiple tasks based on data

Parameters
----------
samples: Train data, see `sedna.datasources.BaseDataSource` for more detail.

Returns
-------
tasks: All tasks based on training data.
task_extractor: Model or dict with a method to predict target tasks
"""

from typing import List, Any, Tuple

from sedna.datasources import BaseDataSource

from ..artifact import Task


class BaseTaskDefinition:
"""
Dividing datasets with all sorts of methods
"""

def __init__(self, **kwargs):
raise NotImplementedError


def __call__(self,
samples: BaseDataSource) -> Tuple[List[Task],
Any,
BaseDataSource]:
raise NotImplementedError
Original file line number Diff line number Diff line change
@@ -4,10 +4,11 @@
from sedna.common.class_factory import ClassType, ClassFactory

from ..artifact import Task
from .base_task_definition import BaseTaskDefinition


@ClassFactory.register(ClassType.STP)
class TaskDefinitionByOrigin:
class TaskDefinitionByOrigin(BaseTaskDefinition):
"""
Dividing datasets based on the their origins.

@@ -18,6 +19,7 @@ class TaskDefinitionByOrigin:
"""

def __init__(self, **kwargs):
super(TaskDefinitionByOrigin, self).__init__()
self.origins = kwargs.get("origins", ["real", "sim"])

def __call__(self,
Original file line number Diff line number Diff line change
@@ -4,10 +4,11 @@
from sedna.common.class_factory import ClassType, ClassFactory

from ..artifact import Task
from .base_task_definition import BaseTaskDefinition


@ClassFactory.register(ClassType.STP)
class TaskDefinitionSimple:
class TaskDefinitionSimple(BaseTaskDefinition):
"""
Dividing datasets based on the their original sites.

@@ -18,6 +19,7 @@ class TaskDefinitionSimple:
"""

def __init__(self, **kwargs):
super(TaskDefinitionSimple, self).__init__()
self.origins = ["front", "garden"]

def __call__(self,
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Discover relationships between all tasks

Parameters
----------
tasks :all tasks form `task_definition`

Returns
-------
task_groups : List of groups which including at least 1 task.
"""

from typing import List

from ..artifact import Task, TaskGroup


class BaseTaskRelationDiscover:
"""
Assume that each task is independent of each other
"""

def __init__(self, **kwargs):
raise NotImplementedError

def __call__(self, tasks: List[Task]) -> List[TaskGroup]:
raise NotImplementedError

Loading