Example #1
0
def main():
    s1 = OrderedStage(f2, size=2)
    s2 = OrderedStage(f3)
    s1.link(s2)
    p = Pipeline(s1)

    def f1():
        for task in [1, 2, 3, 4, 5, None]:
            p.put(task)

    f1()
Example #2
0
def main():
    stage1 = OrderedStage(increment, 3)
    stage2 = OrderedStage(double, 3)
    pipe = Pipeline(stage1.link(stage2))

    for number in range(10):
        pipe.put(number)

    pipe.put(None)

    for result in pipe.results():
        print(result)
Example #3
0
def main():
    stage1 = OrderedStage(increment)
    stage2 = OrderedStage(double)
    stage3 = OrderedStage(echo)
    stage1.link(stage2)
    stage2.link(stage3)
    pipe = Pipeline(stage1)

    for number in range(10):
        pipe.put(number)

    pipe.put(None)
Example #4
0
def main():
    s1 = FilterStage(
        (OrderedStage(pass_thru), ),
        max_tasks=1,
    )
    p1 = Pipeline(s1)

    p2 = Pipeline(OrderedStage(Pull(p1)))
    p2.put(True)

    for number in range(10):
        p1.put(number)
        time.sleep(0.010)

    p1.put(None)
    p2.put(None)
Example #5
0
def main():
    pipe = Pipeline(OrderedStage(echo, 2))
    for number in range(12):
        pipe.put(number)
        time.sleep(0.010)

    pipe.put(None)
Example #6
0
def main():
    stage = FilterStage((OrderedStage(echo), ), max_tasks=2)
    pipe = Pipeline(stage)
    for number in range(12):
        pipe.put(number)
        time.sleep(0.010)

    pipe.put(None)
Example #7
0
def main():
    pipe = Pipeline(OrderedStage(yes, disable_result=True))

    for number in range(10):
        pipe.put(number)
    pipe.put(None)

    for result in pipe.results():
        print(result)
Example #8
0
def extract_feat_from_FCL():
    input_shape = (224, 224, 3)
    model = VGG16(weights='imagenet',
                  input_shape=(input_shape[0], input_shape[1], input_shape[2]),
                  pooling='max',
                  include_top=True)
    t1 = time.time()
    layer_name = "fc2"
    intermediate_layer_model = Model(
        inputs=model.input, outputs=model.get_layer(layer_name).output)

    list = get_imlist("img_cut")

    stage1 = OrderedStage(send_batch)
    stage2 = OrderedStage(create_bag_of_window)
    stage1.link(stage2)
    pipe = Pipeline(stage1)

    batch_size = 1
    total_batch = math.ceil(len(list) / batch_size)

    for p in range(total_batch):
        v = list[p * batch_size:(p + 1) * batch_size]
        print("Batch number %s" % p)
        pipe.put(v)

    pipe.put(None)

    for result in pipe.results():
        t0 = time.time()
        print("Predicting...")
        feature_tensor = intermediate_layer_model.predict(
            np.vstack((r for r in result)))
        t1 = time.time()
        print("time to predict : %ss" % (t1 - t0))
        # gc.collect()
        print(feature_tensor.shape)
        del result

    # feature_tensor = intermediate_layer_model.predict_generator(generator=generator_, steps=1, max_queue_size=1)
    t2 = time.time()
    print("Total time to predict: " + str(t2 - t1))
    print(feature_tensor.shape)
    return feature_tensor
Example #9
0
def main():
    stage = OrderedStage(yes, 4, disable_result=True)
    pipe = Pipeline(stage)

    for number in range(10):
        pipe.put(number)
    pipe.put(None)

    count = 0
    for _ in pipe.results():
        count += 1

    print(count)
Example #10
0
def main():
    stage1 = Stage(Accumulator)
    stage2 = OrderedStage(echo, 50)
    stage1.link(stage2)
    pipe = Pipeline(stage1)

    size = 1000
    prices = np.linspace(0, np.pi * 10, size)
    prices = np.sin(prices) + 1
    for price in prices:
        pipe.put(price)

    pipe.put(None)
Example #11
0
def process():
    list = get_imlist("img_cut/")

    stage1 = OrderedStage(send_batch)
    stage2 = OrderedStage(create_bag_of_window)
    stage3 = OrderedStage(last_stage)
    stage1.link(stage2)
    stage2.link(stage3)
    pipe = Pipeline(stage1)

    batch_size = 20
    total_batch = math.ceil(len(list) / batch_size)

    for p in range(total_batch):
        v = list[p * batch_size:(p + 1) * batch_size]
        print("Batch number %s" % p)
        pipe.put(v)

    pipe.put(None)
Example #12
0
from mpipe import OrderedStage, Pipeline

def increment(value):
    return value + 1

def double(value):
    return value * 2

stage1 = OrderedStage(increment, 3)
stage2 = OrderedStage(double, 3)
pipe = Pipeline(stage1.link(stage2))

for number in range(10):
    pipe.put(number)

pipe.put(None)

for result in pipe.results():
    print(result)
Example #13
0
from mpipe import OrderedStage, Pipeline


def increment(value):
    return value + 1


def double(value):
    return value * 2


stage1 = OrderedStage(increment)
stage2 = OrderedStage(double)
stage1.link(stage2)
pipe = Pipeline(stage1)

for number in range(10):
    pipe.put(number)

pipe.put(None)

for result in pipe.results():
    print(result)
Example #14
0
from mpipe import OrderedStage, UnorderedStage, Pipeline


def increment(value):
    return value + 1


def double(value):
    return value * 2


stage1 = UnorderedStage(increment, 3)
stage2 = OrderedStage(double, 3)
stage1.link(stage2)
pipe = Pipeline(stage1)

for number in range(10):
    pipe.put(number)
pipe.put(None)

for result in pipe.results():
    print(result)
Example #15
0
"""Solution for http://stackoverflow.com/questions/8277715"""

from mpipe import OrderedStage, Pipeline

def f2(value):
    return value * 2

def f3(value):
    print(value)

s1 = OrderedStage(f2, size=2)
s2 = OrderedStage(f3)
s1.link(s2)
p = Pipeline(s1)

def f1():
    for task in [1,2,3,4,5,None]:
        p.put(task)

f1()
Example #16
0
from mpipe import OrderedStage, UnorderedStage, Pipeline


def increment(value):
    return value + 1


def double(value):
    return value * 2


stage1 = OrderedStage(increment, 3)
stage2 = UnorderedStage(double, 3)
stage1.link(stage2)
pipe = Pipeline(stage1)

for number in range(10):
    pipe.put(number)
pipe.put(None)

for result in pipe.results():
    print(result)
Example #17
0
from mpipe import OrderedWorker, Stage, OrderedStage, Pipeline

last10 = deque()
junk = 'http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx/GetQuote?StockSymbol=fac&LicenseKey=0'
j = 'http://www.google.com/ig/api?stock=AAPL'

class Accumulator(OrderedWorker):
    def doTask(self, price):
        if last10:
            if price < min(last10):
                self.putResult(price)
        last10.append(price)
        if len(last10) > 10:
            last10.popleft()

def echo(value):
    print('value = {0}'.format(value))

stage1 = Stage(Accumulator)
stage2 = OrderedStage(echo, 50)
stage1.link(stage2)
pipe = Pipeline(stage1)

SIZE = 1000
prices = np.linspace(0, np.pi*10, SIZE)
prices = np.sin(prices) + 1
for price in prices:
    pipe.put(price)

pipe.put(None)
Example #18
0
import time
from mpipe import OrderedStage, FilterStage, Pipeline


def echo(value):
    print(value)
    time.sleep(0.013)
    return value


stage = FilterStage((OrderedStage(echo), ), max_tasks=2)
pipe = Pipeline(stage)
for number in range(12):
    pipe.put(number)
    time.sleep(0.010)

pipe.put(None)
Example #19
0
from mpipe import OrderedStage, Pipeline


def increment(value):
    return value + 1


def double(value):
    return value * 2


def echo(value):
    print(value)


stage1 = OrderedStage(increment)
stage2 = OrderedStage(double)
stage3 = OrderedStage(echo)
stage1.link(stage2)
stage2.link(stage3)
pipe = Pipeline(stage1)

for number in range(10):
    pipe.put(number)

pipe.put(None)
Example #20
0
        results = np.zeros((1280, 800))  # prefilled array
        i = 0
        counter = 0
        feature_detect = False
        #t_end = time.time()+1
        #while(time.time()<t_end):
        #   try:
        for i in range(max_frames):
            frame = camera.capture(encoding="raw")
            ls[i] = frame.as_array.reshape(1280, 800)
            print(i)

        t.start()
        background = ls[0]
        current = ls[1]
        stage1 = OrderedStage(increment, ls_shape[0] * ls_shape[1])
        pipe = Pipeline(stage1)
        for i in range(ls_shape[0]):
            for j in range(ls_shape[1]):
                pipe.put(background[i][j], current[i][j])

        pipe.put(None)
        for result in pipe.results():
            counter += results
        if (counter > pix_threshold):
            feature_detect = True
        t.stop()

        camera.close_camera()
        if (feature_detect):
            for i in range(max_frames):
Example #21
0
from mpipe import OrderedStage, FilterStage, Pipeline
import time


def echo(value):
    print(value)
    time.sleep(0.0125)
    return value


pipe1 = Pipeline(FilterStage((OrderedStage(echo), ), max_tasks=2))


def pull(task):
    for result in pipe1.results():
        pass


pipe2 = Pipeline(OrderedStage(pull))
pipe2.put(True)
pipe2.put(None)

for number in range(10):
    pipe1.put(number)
    time.sleep(0.0100)

pipe1.put(None)
Example #22
0
from mpipe import OrderedStage, Pipeline


def increment(value):
    return value + 1


def double(value):
    return value * 2


stage1 = OrderedStage(increment, 3)
stage2 = OrderedStage(double, 3)
pipe = Pipeline(stage1.link(stage2))

for number in range(10):
    pipe.put(number)

pipe.put(None)

for result in pipe.results():
    print(result)
Example #23
0
import time
from mpipe import OrderedStage, FilterStage, Pipeline


def passthru(value):
    time.sleep(0.013)
    return value


s1 = FilterStage(
    (OrderedStage(passthru), ),
    max_tasks=1,
    cache_results=True,
)
p1 = Pipeline(s1)


def pull(task):
    for task, result in p1.results():
        if result:
            print('{0} {1}'.format(task, result[0]))


p2 = Pipeline(OrderedStage(pull))
p2.put(True)

for number in range(10):
    p1.put(number)
    time.sleep(0.010)

p1.put(None)
Example #24
0
from mpipe import OrderedStage, Pipeline


def yes(value):
    return value


pipe = Pipeline(OrderedStage(yes, disable_result=True))

for number in range(10):
    pipe.put(number)

pipe.put(None)

for result in pipe.results():
    print(result)
Example #25
0
from mpipe import OrderedStage, Pipeline

def increment(value):
    return value + 1

def double(value):
    return value * 2

def echo(value):
    print(value)

stage1 = OrderedStage(increment)
stage2 = OrderedStage(double)
stage3 = OrderedStage(echo)
stage1.link(stage2)
stage2.link(stage3)
pipe = Pipeline(stage1)

for number in range(10):
    pipe.put(number)

pipe.put(None)
Example #26
0
from mpipe import OrderedStage, Pipeline


def yes(value):
    return value


stage = OrderedStage(yes, 4, disable_result=True)
pipe = Pipeline(stage)

for number in range(10):
    pipe.put(number)

pipe.put(None)

count = 0
for result in pipe.results():
    count += 1

print(count)
Example #27
0
import time
from mpipe import OrderedStage, Pipeline


def echo(value):
    print(value)
    time.sleep(0.013)
    return value


pipe = Pipeline(OrderedStage(echo))
for number in range(12):
    pipe.put(number)
    time.sleep(0.010)

pipe.put(None)
Example #28
0
"""Solution for http://stackoverflow.com/questions/8277715"""

from mpipe import OrderedStage, Pipeline


def f2(value):
    return value * 2


def f3(value):
    print(value)


s1 = OrderedStage(f2, size=2)
s2 = OrderedStage(f3)
s1.link(s2)
p = Pipeline(s1)


def f1():
    for task in [1, 2, 3, 4, 5, None]:
        p.put(task)


f1()