예제 #1
0
파일: main.py 프로젝트: Judithsq/samples
def create_threads(detector):
    config = configparser.ConfigParser()
    config.read(FACE_DETEC_CONF)

    video_decoders = []
    for item in config['videostream']:
        preprocesser = Preprocess(config['videostream'][item],
                                  len(video_decoders), MODEL_WIDTH,
                                  MODEL_HEIGHT)
        video_decoders.append(preprocesser)

    rtsp_num = len(video_decoders)
    if rtsp_num == 0:
        log_error("No video stream name or addr configuration in ",
                  FACE_DETEC_CONF)
        return None, None

    postprocessor = Postprocess(detector)

    display_channel = int(config['display']['channel'])
    if (display_channel is None) or (display_channel >= rtsp_num):
        log_info("No video to display, display configuration: ",
                 config['display']['channel'])
    else:
        video_decoders[display_channel].set_display(True)
        ret = postprocessor.create_presenter_channel(FACE_DETEC_CONF)
        if ret == False:
            log_error("Create presenter channel failed")
            return None, None

    return video_decoders, postprocessor
예제 #2
0
def run_single_block(input_list):
	baseName,model,out_dir,rst,window,keep_temp,threshold,penality,DB_file,input_file,chromosome,strand,fa_file,depth,start,end = input_list

	print("Generating blocks ...%s %d %s"%(baseName,start,end))
	####Generate sliding windlows
	gw_start_time = datetime.datetime.now()
	block = split_chr_bedGraph2(out_dir,input_file,chromosome,strand,window,fa_file,depth,start,end)
	#ww = open(baseName,'w')
	#for a,b,c in block:
	#	ww.write('%s\t%s\t%s\n'%(a,b,c))
	#ww.close()
	gw_end_time = datetime.datetime.now()
	print("Generate blocks used time: {}".format(gw_end_time - gw_start_time))

	print("Evaluating blocks ...%s %d %s"%(baseName,start,end))
	gw_start_time = datetime.datetime.now()
	Evaluate(baseName,block,model,out_dir,rst,window,keep_temp)
	gw_end_time = datetime.datetime.now()
	print("Evaluated blocks used time: {}".format(gw_end_time - gw_start_time))

	Scan_Forward(baseName,threshold,penality,out_dir)
	Scan_Backward(baseName,threshold,penality,out_dir)
	if(keep_temp != 'yes'):
		predict_file = out_dir+'/predict/'+baseName+'.txt'
		os.system('rm %s'%predict_file)
	Postprocess(DB_file,baseName,threshold,penality,out_dir)
	if(keep_temp != 'yes'):
		forward_file=out_dir+"/maxSum/%s.forward.%d.%d.txt"%(baseName,threshold,penality)
		backward_file=out_dir+"/maxSum/%s.backward.%d.%d.txt"%(baseName,threshold,penality)
		os.system('rm %s %s'%(forward_file,backward_file))
	print('Finished postprocessing...\n')
예제 #3
0
def run_single_block(input_list):
    data = input_list[0]
    model = input_list[1]
    out_dir = input_list[2]
    rst = input_list[3]
    window = input_list[4]
    keep_temp = input_list[5]
    threshold = input_list[6]
    penality = input_list[7]
    DB_file = input_list[8]
    if 'wig' not in data:
        baseName = data.split('/')[-1]
        Evaluate(model, out_dir, rst, window, baseName, keep_temp)
        Scan_Forward(baseName, threshold, penality, out_dir)
        Scan_Backward(baseName, threshold, penality, out_dir)
        if (keep_temp != 'yes'):
            predict_file = out_dir + '/predict/' + baseName + '.txt'
            os.system('rm %s' % predict_file)
        Postprocess(DB_file, baseName, threshold, penality, out_dir)
        if (keep_temp != 'yes'):
            forward_file = out_dir + "/maxSum/%s.forward.%d.%d.txt" % (
                baseName, threshold, penality)
            backward_file = out_dir + "/maxSum/%s.backward.%d.%d.txt" % (
                baseName, threshold, penality)
            os.system('rm %s %s' % (forward_file, backward_file))
        print('Finished postprocessing...\n')
def run_single_block(input_list):
    #global ref
    #print(ref.keys())
    baseName, model, out_dir, rst, window, keep_temp, threshold, penality, DB_file, input_file, fa_file, chromosome, strand, depth, start, end = input_list

    #log_dir = out_dir+'/log'
    #if not os.path.exists(log_dir):
    #    os.makedirs(log_dir)
    #log.basicConfig(filename='%s/%s.log'%(log_dir,baseName), level=log.INFO)
    print("Generating blocks ...%s %d %s" % (baseName, start, end))
    ####Generate sliding windlows
    gw_start_time = datetime.datetime.now()
    block = split_chr_bedGraph2(out_dir, input_file, chromosome, strand,
                                window, fa_file, depth, start, end)
    #ww = open(baseName,'w')
    #for a,b,c in block:
    #    ww.write('%s\t%s\t%s\n'%(a,b,c))
    #ww.close()
    gw_end_time = datetime.datetime.now()
    print("Generate blocks used time: {}\n".format(gw_end_time -
                                                   gw_start_time))

    print("Evaluating blocks ...%s %d %s" % (baseName, start, end))
    ev_start_time = datetime.datetime.now()
    Evaluate(baseName, block, model, out_dir, rst, window, keep_temp)

    del block  #destroyed the block reference
    gc.collect()  #manually run garbage collection process

    ev_end_time = datetime.datetime.now()
    print("Evaluated blocks used time: {}\n".format(ev_end_time -
                                                    ev_start_time))

    print("Postprocessing blocks ...%s %d %s" % (baseName, start, end))
    ps_start_time = datetime.datetime.now()
    Scan_Forward(baseName, threshold, penality, out_dir)
    Scan_Backward(baseName, threshold, penality, out_dir)
    if (keep_temp != 'yes'):
        predict_file = out_dir + '/predict/' + baseName + '.txt'
        os.system('rm %s' % predict_file)
    Postprocess(DB_file, baseName, threshold, penality, out_dir)
    ps_end_time = datetime.datetime.now()
    print("Postprocessed blocks used time: {}\n".format(ps_end_time -
                                                        ps_start_time))

    if (keep_temp != 'yes'):
        forward_file = out_dir + "/maxSum/%s.forward.%d.%d.txt" % (
            baseName, threshold, penality)
        backward_file = out_dir + "/maxSum/%s.backward.%d.%d.txt" % (
            baseName, threshold, penality)
        os.system('rm %s %s' % (forward_file, backward_file))
    #print('Finished postprocessing...%s\n'%baseName)
    return [
        gw_end_time - gw_start_time, ev_end_time - ev_start_time,
        ps_end_time - ps_start_time
    ]
예제 #5
0
def run_single_block(input_list):
    baseName, model, out_dir, rst, window, keep_temp, threshold, penality, DB_file, input_file, strand, depth, block_pos = input_list
    chromosome = block_pos[3]
    start = block_pos[4]
    end = block_pos[5]
    print("Generating blocks ...%s %d %s" %
          (baseName, block_pos[4], block_pos[5]))
    ####Generate sliding windlows
    gw_start_time = datetime.datetime.now()
    blocks = Bedgraph_to_blocks(input_file, fa_file, window, depth, block_pos)
    #ww = open(baseName,'w')
    #for a,b,c in blocks:
    #    ww.write('%s\t%s\t%s\n'%(a,b,c))
    #ww.close()
    gw_end_time = datetime.datetime.now()
    print("Generate blocks used time: {}\n".format(gw_end_time -
                                                   gw_start_time))

    print("Evaluating blocks ...%s %d %s" % (baseName, start, end))
    ev_start_time = datetime.datetime.now()
    Evaluate(baseName, blocks, model, out_dir, rst, window, keep_temp)

    del blocks  #destroyed the block reference
    gc.collect()  #manually run garbage collection process

    ev_end_time = datetime.datetime.now()
    print("Evaluated blocks used time: {}\n".format(ev_end_time -
                                                    ev_start_time))

    print("Postprocessing blocks ...%s %d %s" % (baseName, start, end))
    ps_start_time = datetime.datetime.now()
    Scan_Forward(baseName, threshold, penality, out_dir)
    Scan_Backward(baseName, threshold, penality, out_dir)
    if (keep_temp != 'yes'):
        predict_file = out_dir + '/predict/' + baseName + '.txt'
        os.system('rm %s' % predict_file)
    Postprocess(DB_file, baseName, threshold, penality, out_dir)
    ps_end_time = datetime.datetime.now()
    print("Postprocessed blocks used time: {}\n".format(ps_end_time -
                                                        ps_start_time))

    if (keep_temp != 'yes'):
        forward_file = out_dir + "/maxSum/%s.forward.%d.%d.txt" % (
            baseName, threshold, penality)
        backward_file = out_dir + "/maxSum/%s.backward.%d.%d.txt" % (
            baseName, threshold, penality)
        os.system('rm %s %s' % (forward_file, backward_file))
    #print('Finished postprocessing...%s\n'%baseName)
    return [
        gw_end_time - gw_start_time, ev_end_time - ev_start_time,
        ps_end_time - ps_start_time
    ]
예제 #6
0
파일: main.py 프로젝트: Ascend/samples
def create_threads(detector):
    """create threads"""
    config = configparser.ConfigParser()
    config.read(COCO_DETEC_CONF)
    video_decoders = []
    for item in config['videostream']:
        preprocesser = Preprocess(config['videostream'][item],
                                  len(video_decoders), MODEL_WIDTH,
                                  MODEL_HEIGHT)
        video_decoders.append(preprocesser)

    rtsp_num = len(video_decoders)
    if rtsp_num == 0:
        log_error("No video stream name or addr configuration in ",
                  COCO_DETEC_CONF)
        return None, None

    postprocessor = Postprocess(detector)

    return video_decoders, postprocessor
def main(out_dir, input_file, input_plus, input_minus, fa_file, keep_temp,
         window, name, model, rst, threshold, penality, DB_file):

    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    out_dir = out_dir + '/' + name
    ####Generate sliding windlows
    Generate_windows(out_dir, input_file, input_plus, input_minus, fa_file,
                     keep_temp, window, name)

    data_dir = out_dir + '/data'
    data_files = glob.glob(data_dir + "/*")
    for data in data_files:
        if 'wig' in data:
            continue
        baseName = data.split('/')[-1]
        Evaluate(model, out_dir, rst, window, baseName, keep_temp)
        Scan_Forward(baseName, threshold, penality, out_dir)
        Scan_Backward(baseName, threshold, penality, out_dir)
        if (keep_temp != 'yes'):
            predict_file = out_dir + '/predict/' + baseName + '.txt'
            os.system('rm %s' % predict_file)
        Postprocess(DB_file, baseName, threshold, penality, out_dir)
        if (keep_temp != 'yes'):
            forward_file = out_dir + "/maxSum/%s.forward.%d.%d.txt" % (
                baseName, threshold, penality)
            backward_file = out_dir + "/maxSum/%s.backward.%d.%d.txt" % (
                baseName, threshold, penality)
            os.system('rm %s %s' % (forward_file, backward_file))

    out_file = '%s/%s.predicted.txt' % (out_dir, name)
    ww = open(out_file, 'w')
    ww.write('predicted_pasid\tdb_diff\tdb_pasid\tscore\n')
    ww.close()
    os.system('cat %s/maxSum/*bidirection* >>%s' % (out_dir, out_file))
    if (keep_temp != 'yes'):
        os.system('rm -rf %s/data %s/predict %s/maxSum' %
                  (out_dir, out_dir, out_dir))

    print("Job Done!")
예제 #8
0
                        outputFile.write('\t'.join(outputLine) + '\n')
                    outputFile.write('\n')

                    sentence = []
                    tags = []
                    continue
                else:
                    token, label = line.split('\t')
                    sentence.append(token)
                    tags.append(label)


if __name__ == '__main__':
    crf_path = 'E:/data/CRF++-0.54/'
    crf_data_path = 'crf_input/'

    para = 'trigger'

    os.system(
        '{}crf_learn -a MIRA -f 5 {}template.txt {}{para}_train.txt {para}_model'
        .format(crf_path, crf_data_path, crf_data_path, para=para))

    if para == 'trigger':
        os.system('{}crf_test -m model -v2 {}{para}_test.txt > {para}_raw.txt'.
                  format(crf_path, crf_data_path, para=para))
        Postprocess().processOutput('trigger_raw.txt', 'trigger_result.txt')
    else:
        os.system(
            '{}crf_test -m {para}_model {}{para}_test.txt > {para}_result.txt'.
            format(crf_path, crf_data_path, para=para))
예제 #9
0
img = cv2.imread('./data/VOC2007_trainval/JPEGImages/000017.jpg')
img = cv2.resize(img, (416, 416))
x = torch.from_numpy(img / 255).float().unsqueeze(0).permute(0, -1, 1,
                                                             2).cuda()

model = YoloV3(num_classes)
state = torch.load(os.path.join(saved_pth_dir, pth_file))

model.load_state_dict(state['model_state_dict'])
model.eval()
model.cuda()

y_pred = model(x, training=False)

postprocessor = Postprocess(iou_threshold=0.5,
                            score_threshold=0.5,
                            max_detection=10).cuda()
boxes, scores, classes, num_detection = postprocessor(y_pred)

num_img = num_detection.shape[0]

for n_img in range(num_img):
    h, w, c = img.shape
    score = scores.cpu()[n_img]

    classs = classes.cpu()[n_img]
    classs = torch.argmax(classs, dim=1)

    for i in range(num_detection.item()):
        box = boxes.cpu()[n_img][i]
        score_value = score[i].item()
예제 #10
0
def VGGish(pump=None,
           input_shape=None,
           include_top=False,
           pooling='avg',
           weights='audioset',
           name='vggish',
           compress=False):
    '''A Keras implementation of the VGGish architecture.

    Arguments:
        pump (pumpp.Pump): The model pump object.

        input_shape (tuple): the model input shape. If ``include_top``,
            ``input_shape`` will be set to ``(params.NUM_FRAMES, params.NUM_BANDS, 1)``,
            otherwise it will be ``(None, None, 1)`` to accomodate variable sized
            inputs.

        include_top (bool): whether to include the fully connected layers. Default is False.

        pooling (str): what type of global pooling should be applied if no top? Default is 'avg'

        weights (str, None): the weights to use (see WEIGHTS_PATHS). Currently, there is
            only 'audioset'. Can also be a path to a keras weights file.

        name (str): the name for the model.

    Returns:
        A Keras model instance.
    '''

    with tf.name_scope(name):
        if input_shape:
            pass

        elif include_top:
            input_shape = params.NUM_FRAMES, params.NUM_BANDS, 1

        elif pump:
            # print(type(pump))
            inputs = pump.layers('tf.keras')[params.PUMP_INPUT]

        else:
            input_shape = None, None, 1

        # use input_shape to make input
        if input_shape:
            inputs = tfkl.Input(shape=input_shape, name='input_1')

        # setup layer params
        conv = partial(
            tfkl.Conv2D,
            kernel_size=(3, 3), strides=(1, 1), activation='relu', padding='same')

        maxpool = partial(
            tfkl.MaxPooling2D, pool_size=(2, 2), strides=(2, 2), padding='same')

        # Block 1
        x = conv(64, name='conv1')(inputs)
        x = maxpool(name='pool1')(x)

        # Block 2
        x = conv(128, name='conv2')(x)
        x = maxpool(name='pool2')(x)

        # Block 3
        x = conv(256, name='conv3/conv3_1')(x)
        x = conv(256, name='conv3/conv3_2')(x)
        x = maxpool(name='pool3')(x)

        # Block 4
        x = conv(512, name='conv4/conv4_1')(x)
        x = conv(512, name='conv4/conv4_2')(x)
        x = maxpool(name='pool4')(x)

        if include_top:
            dense = partial(tfkl.Dense, activation='relu')

            # FC block
            x = tfkl.Flatten(name='flatten_')(x)
            x = dense(4096, name='fc1/fc1_1')(x)
            x = dense(4096, name='fc1/fc1_2')(x)
            x = dense(params.EMBEDDING_SIZE, name='fc2')(x)

            if compress:
                x = Postprocess()(x)
        else:
            globalpool = (
                tfkl.GlobalAveragePooling2D() if pooling == 'avg' else
                tfkl.GlobalMaxPooling2D() if pooling == 'max' else None)

            if globalpool:
                x = globalpool(x)

        # Create model
        model = Model(inputs, x, name='model')
        # print(model.summary())
        model.load_weights('/scratch/mkolpe2s/CNN_dcase/vggish_audioset_weights_without_fc2.h5')
        # load_vggish_weights(model, weights, strict=bool(weights))
        # print("Okay")
    return model
예제 #11
0
from crawler import Crawler
from preprocess_purchase import PreprocessPurchase
from inference import Inference
from learning_purchase import Learning
from postprocess import Postprocess, Email
from datetime import datetime

data_version = datetime.now().strftime("%Y%m%d")
load_date = data_version
target = 'purchase'
mode = 'inference'
encoder_version = 'original'
model_version = 'original'

#crawling
crawler = Crawler(data_version, target)
#preprocess
prep = PreprocessPurchase(mode, data_version, encoder_version)
#inference
inf = Inference(data_version, model_version)
#postprocess
post = Postprocess(data_version, model_version)
body = post.urls()
em = Email()
msg = em.create_message(body)
em.send(msg)
예제 #12
0
파일: game.py 프로젝트: wezu/pyweek21
    def setup(self):
        self.worldNP = render.attachNewNode('World')

        # World
        self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
        self.debugNP.hide()

        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        self.world.setDebugNode(self.debugNP.node())

        # Plane
        #shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
        #mesh = BulletTriangleMesh()
        #geomNodes = loader.loadModel('levels/test1/collision').findAllMatches('**/+GeomNode')
        #geomNode = geomNodes.getPath(0).node()
        #geom = geomNode.getGeom(0)
        #mesh.addGeom(geom)
        #shape = BulletTriangleMeshShape(mesh, dynamic=False, bvh=True )
        #np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
        #np.node().addShape(shape)
        #np.setPos(0, 0, 20.0)
        #np.setCollideMask(BitMask32.allOn())
        #self.world.attachRigidBody(np.node())

        #sky dome
        self.sun_sky = Sky()
        self.sun_sky.setTime(17.0)

        #terrain
        self.ground = Terrain(self.world, self.worldNP)
        self.ground.loadMesh(path + 'levels/gandg2/collision')
        self.ground.setMaps(path + 'levels/gandg2/')
        self.ground.setTextures((39, 1, 2, 15, 4, 5))

        #grass
        self.grass = Grass()
        self.grass.setMap(path + 'levels/gandg2/grass.png')
        self.grass_to_cut = self.grass.getStatus()
        # Car
        self.car = Car(self.world, self.worldNP)
        self.car.setPos(161.0, 160.0, 26)
        #camera
        self.camera = FlyingCamera()

        #car to character scale 0.0128
        self.char = Character(self.world, self.worldNP)
        self.char.enterCar()
        #self.char.setPos(256, 250, 80)

        #filter manager, post process
        self.filters = Postprocess()
        #self.filters.setupFxaa()
        #no time to make it work, sorry...
        self.filters.setupFilters()

        #map objects .. hardcoded because of time
        self.object_root = render.attachNewNode('object_root')
        obj = [(path + 'models/pyweek_wall1', 0.0, (303.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (301.0, 405.0,
                                                    25.0980434417725),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (299.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (297.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (295.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (293.0, 405.0,
                                                    25.0980434417725),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (291.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (289.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (287.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (285.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (283.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (281.0, 405.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (281.0, 385.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (283.0, 385.0,
                                                    25.0980453491211),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (285.0, 385.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 404.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 402.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 400.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 398.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 396.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 394.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (304.0, 392.0,
                                                     25.237850189209),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 404.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 398.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 396.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 394.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 392.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 390.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 388.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 386.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (286.0, 386.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (286.0, 388.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (286.0, 390.0,
                                                     25.0980434417725),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (287.0, 391.0,
                                                    25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (289.0, 391.0,
                                                    25.1190624237061),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (291.0, 391.0,
                                                    25.1960334777832),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (293.0, 391.0,
                                                    25.1596641540527),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (295.0, 391.0,
                                                    25.2697868347168),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (297.0, 391.0,
                                                    25.3282146453857),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (299.0, 391.0,
                                                    25.3496627807617),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (301.0, 391.0,
                                                    25.2688617706299),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 0.0, (303.0, 391.0,
                                                    25.2534332275391),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_wall1', 90.0, (280.0, 402.0,
                                                     25.0980415344238),
                path + 'models/pyweek_wall1_collision'),
               (path + 'models/pyweek_box', 0.0,
                (279.600006103516, 401.700012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (279.399993896484, 402.200012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (279.600006103516, 402.700012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (279.399993896484, 403.399993896484, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (278.799987792969, 402.799987792969, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (278.799987792969, 402.100006103516, 25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0, (279.0, 401.5,
                                                  25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0, (278.5, 401.600006103516,
                                                  25.0980415344238), None),
               (path + 'models/pyweek_box', 0.0,
                (278.799987792969, 401.899993896484, 25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.5, 402.600006103516,
                                                   25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.0, 402.5,
                                                   25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.399993896484, 402.0,
                                                   25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (278.100006103516, 402.299987792969, 25.0980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (277.799987792969, 401.700012207031, 25.0980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (278.200012207031, 401.899993896484, 25.5980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (279.399993896484, 402.399993896484, 26.0980415344238), None),
               (path + 'models/pyweek_box', 90.0, (279.0, 401.899993896484,
                                                   26.0980415344238), None),
               (path + 'models/pyweek_box', 90.0,
                (278.799987792969, 402.399993896484, 26.0980415344238), None)]
        for i in obj:
            loadObject(model=i[0],
                       H=i[1],
                       pos=i[2],
                       world=self.world,
                       worldNP=self.worldNP,
                       root=self.object_root,
                       collision_solid=i[3])
        self.object_root.flattenStrong()

        #models/pyweek_gate,90.0,(280.0,399.0,25.0980415344238))

        #gui
        self.hud = HUD()

        #volume
        sfxMgr = base.sfxManagerList[0]
        sfxMgr.setVolume(cfg['sound-volume'] * 0.01)
        musicMgr = base.musicManager
        musicMgr.setVolume(cfg['music-volume'] * 0.01)

        #music
        self.driving_music = loader.loadMusic(path + 'music/driving.ogg')
        self.driving_music.setLoop(True)
        self.driving_music.play()
        self.walking_music = loader.loadMusic(path + 'music/walking.ogg')
        self.walking_music.setLoop(True)

        print self.char.actor.getScale(render)
예제 #13
0
	Generate_windows(out_dir,input_file,input_plus,input_minus,fa_file,keep_temp,window,name,depth)
>>>>>>> e6e9d5b305368adbd0eec6e055e70e82e740a154
	
	data_dir = out_dir+'/data'
	data_files = glob.glob(data_dir+"/*")
	for data in data_files:
		if 'wig' in data:
			continue
		baseName = data.split('/')[-1]
		Evaluate(model,out_dir,rst,window,baseName,keep_temp)
		Scan_Forward(baseName,threshold,penality,out_dir)
		Scan_Backward(baseName,threshold,penality,out_dir)
		if(keep_temp != 'yes'):
			predict_file = out_dir+'/predict/'+baseName+'.txt'
			os.system('rm %s'%predict_file)
		Postprocess(DB_file,baseName,threshold,penality,out_dir)
		if(keep_temp != 'yes'):
			forward_file=out_dir+"/maxSum/%s.forward.%d.%d.txt"%(baseName,threshold,penality)
			backward_file=out_dir+"/maxSum/%s.backward.%d.%d.txt"%(baseName,threshold,penality)
			os.system('rm %s %s'%(forward_file,backward_file))

	out_file = '%s/%s.predicted.txt' %(out_dir,name)
	ww = open(out_file,'w')
<<<<<<< HEAD
	ww.write('predicted_pasid\tdb_diff\tdb_pasid\tscore\n')
=======
	if(DB_file is not None): 
		ww.write('predicted_pasid\tdb_pasid\tdb_diff\tscore\n')
	else:
		ww.write('predicted_pasid\tscore\n')
>>>>>>> e6e9d5b305368adbd0eec6e055e70e82e740a154
예제 #14
0
def VGGish(pump=None,
           input_shape=None,
           include_top=False,
           pooling='avg',
           weights='audioset',
           name='vggish',
           compress=False):

    with tf.name_scope(name):
        if input_shape:
            pass

        elif pump:
            inputs = pump.layers('tf.keras')[params.PUMP_INPUT]

        elif include_top:
            input_shape = params.NUM_FRAMES, params.NUM_BANDS, 1

        else:
            input_shape = None, None, 1

        # use input_shape to make input
        if input_shape:
            inputs = kl.Input(shape=input_shape, name='input_1')

        # setup layer params
        conv = partial(
            kl.Conv2D,
            kernel_size=(3, 3), strides=(1, 1), activation='relu', padding='same')

        maxpool = partial(
            kl.MaxPooling2D, pool_size=(2, 2), strides=(2, 2), padding='same')

        # Block 1
        x = conv(64, name='conv1')(inputs)
        x = maxpool(name='pool1')(x)

        # Block 2
        x = conv(128, name='conv2')(x)
        x = maxpool(name='pool2')(x)

        # Block 3
        x = conv(256, name='conv3/conv3_1')(x)
        x = conv(256, name='conv3/conv3_2')(x)
        x = maxpool(name='pool3')(x)

        # Block 4
        x = conv(512, name='conv4/conv4_1')(x)
        x = conv(512, name='conv4/conv4_2')(x)
        x = maxpool(name='pool4')(x)

        if include_top:
            dense = partial(kl.Dense, activation='relu')

            # FC block
            x = kl.Flatten(name='flatten_')(x)
            x = dense(4096, name='fc1/fc1_1')(x)
            x = dense(4096, name='fc1/fc1_2')(x)
            x = dense(params.EMBEDDING_SIZE, name='fc2')(x)

            if compress:
                x = Postprocess()(x)
        else:
            globalpool = (
                kl.GlobalAveragePooling2D() if pooling == 'avg' else
                kl.GlobalMaxPooling2D() if pooling == 'max' else None)

            if globalpool:
                x = globalpool(x)

        # Create model
        model = Model(inputs, x, name='model')
        load_vggish_weights(model, weights, strict=bool(weights))
    return model
예제 #15
0
    def predict(self):
        time_preprocess = TimeCalculation(name='Preprocess')
        time_predict = TimeCalculation(name='Predict')
        time_postprocess = TimeCalculation(name='Postprocess')
        time_total = TimeCalculation(name='Total')

        # 总计时开始
        time_total.begin()

        # 预处理计时开始
        time_preprocess.begin()

        # dicom 转换成 nii, 如果 nii_path 有值, 则默认不需要转换,直接去 nii_path 作为 origin_nii_path
        print('------------>> step1: dicom2nii...')

        origin_nii_path = self.nii_path if self.nii_path else dicom2nii(
            dicom_path=self.dicom_path, save_path=self.output_path)

        origin_nii = image.load_img(origin_nii_path)

        print('------> origin nii shape: ' + str(origin_nii.get_data().shape))

        # 预处理
        print('------------>> step2: preprocrss...')
        r_nii_data, main_axis, padding = PreProcess4MSpacing.preprocess(
            origin_nii, self.standard_shape, normalize='standardiztion')
        x_padding = padding[0]
        y_padding = padding[1]
        z_padding = padding[2]

        # 预处理计时结束
        time_preprocess.end()

        # 预测计时开始
        time_predict.begin()

        # 载入模型
        print('------------>> step3: load model...')
        model = self.load_model()

        # 开始预测
        print('------------>> step4: start to predict...')

        # 计算分块取数据需要的步骤数
        step = int(math.ceil(r_nii_data.shape[0] / self.standard_shape[0]))
        print('------> generator steps: ' + str(step))

        pre_imgs = model.predict_generator(generator=GeneratorMSpacing(
            normalize_func=PreProcess4MSpacing.standardiztion).pre_generator(
                r_nii_data),
                                           steps=step)
        # 预测计时结束
        time_predict.end()

        # 后处理计时开始
        time_postprocess.begin()

        output_imgs = np.argmax(pre_imgs, axis=4)

        # 巨坑:输出图像前把类型转换成float32,不然MRIcorN显示的时候会出现问题
        output_imgs = output_imgs.astype(np.float32)
        print('------> output image shape: ' + str(output_imgs.shape))
        print('------> unique of output image: ' + str(np.unique(output_imgs)))

        # 输出图像并保存
        print('------------>> step5: stitching_predicted_data...')
        stitching_data = self.stitching_predicted_data(output_imgs,
                                                       self.standard_shape)

        # 还原 padding 的数据
        print(stitching_data.shape)
        stitching_data = stitching_data[:(
            stitching_data.shape[0] -
            x_padding[1]), :(stitching_data.shape[1] -
                             y_padding[1]), :(stitching_data.shape[2] -
                                              z_padding[1])]

        print('------> not padding output shape: ' + str(stitching_data.shape))

        # 主轴还原
        transpose_shape_dict = {0: (0, 1, 2), 1: (1, 0, 2), 2: (1, 2, 0)}
        stitching_data = np.transpose(stitching_data,
                                      transpose_shape_dict[main_axis])

        print(np.unique(stitching_data))

        predict_nii = np_2_nii(origin_nii_path,
                               stitching_data,
                               need_save=False)

        print('------------>> step6: postprocess...')
        Postprocess(predict_nii, origin_nii, origin_nii_path,
                    self.output_path).postprocess()

        # 输出 nii 图像
        print('------> output nii file...')
        self.output_nii(predict_nii, origin_nii)
        self.output_nii(predict_nii, origin_nii, 1)
        self.output_nii(predict_nii, origin_nii, 2)
        self.output_nii(predict_nii, origin_nii, 3)

        # 计算 dice 值
        self.calculate_dice(predict_nii)

        # 后处理计时结束
        time_postprocess.end()

        # 总计时结束
        time_total.end()
        print('------------>> Done!')