コード例 #1
0
def viz_textbb(name,text_im, charBB_list, wordBB,senBB, alpha=1.0):
    """
    text_im : image containing text
    charBB_list : list of 2x4xn_i bounding-box matrices
    wordBB : 2x4xm matrix of word coordinates
    """
    plt.close(1)
    plt.figure(1,figsize=(15,15))
    plt.imshow(text_im)
    H,W = text_im.shape[:2]

    # plot the character-BB:
    # for i in range(len(charBB_list)):
    #     bbs = charBB_list[i]
    #     ni = bbs.shape[-1]
    #     for j in range(ni):
    #         bb = bbs[:,:,j]
    #         bb = np.c_[bb,bb[:,0]]
    #         plt.plot(bb[0,:], bb[1,:], 'r', alpha=alpha/2)

    # # plot the word-BB:
    # for i in range(wordBB.shape[-1]):
    #     bb = wordBB[:,:,i]
    #     bb = np.c_[bb,bb[:,0]]
    #     plt.plot(bb[0,:], bb[1,:], 'g', alpha=alpha)
    #     # visualize the indiv vertices:
    #     vcol = ['r','g','b','k']
    #     for j in range(4):
    #         plt.scatter(bb[0,j],bb[1,j],color=vcol[j])

    for i in range(senBB.shape[-1]):
        bb = senBB[:,:,i]
        bb = np.c_[bb,bb[:,0]]
        plt.plot(bb[0,:], bb[1,:], 'g', alpha=alpha)
        # visualize the indiv vertices:
        vcol = ['r','g','b','k']
        for j in range(4):
            plt.scatter(bb[0,j],bb[1,j],color=vcol[j])

    plt.gca().set_xlim([0,W-1])
    plt.gca().set_ylim([H-1,0])
    # plt.show(block=False)
    plt.savefig('img/' + name + '.jpg')
コード例 #2
0
            number = get_all_sheets(in_file, raw_file)
            pages = range(1, number + 1)

            for i in pages:
                raw_sheet = raw_file + '_Tank_' + str(i) + '.xls'
                X_min, X_max, Y_min, Y_max, scaler = scale(
                    X_length, raw_sheet, frames, start, end)

                # important to not mess up:
                X0 = X_min + dist_from_wall
                Xn = X_max - dist_from_wall
                Y0 = Y_min + dist_from_wall
                Yn = Y_max - dist_from_wall
                Y_half = (Y_max - Y_min) / 2
                Y_fourth = (Y_max - Y_min) / 4
                Y_third = (Y_max - Y_min) / 3
                Y_half_lim = Y_max - Y_half
                Y_fourth_lim = Y_max - Y_fourth
                Y_3fourth_lim = Y_max - 3 * (Y_fourth)
                Y_third_lim = Y_max - Y_third

                file_name = raw_file + '_Tank_' + str(i)
                xls_input = raw_sheet + '.txt'
                XY = heat_map(X0, Xn, Y0, Yn, xls_input, frame_rate,
                              Y_half_lim, Y_fourth_lim, Y_3fourth_lim,
                              Y_third_lim, file_name, name)

        calc("output/Extracted_data_" + name + ".xls")
        plot("output/Extracted_data_" + name + ".xls", name)
        os.chdir(og)
コード例 #3
0
    #Metadata metrics:
    [VIDEO_FPS, Metric, METADATA],
    [VIDEO_NUM_FRAMES, Metric, METADATA],
    [VIDEO_SAMPLING_INTERVAL, Metric, METADATA],
    [AUDIO_FPS, Metric, METADATA],
    [AUDIO_NUM_SAMPLES, Metric, METADATA],
    [AUDIO_SAMPLING_INTERVAL, Metric, METADATA],
    
    #Other metrics:
    [AUDIO_TRACE, TimeMetric, AUDIO, identity, ag(AUDIO_SAMPLING_INTERVAL)],
]

mm = VideoMetricsManager(f, NpyStorageInterface(), metrics_definitions,
                         metrics_dict={})
mm.get_metrics([VIDEO_NUM_FRAMES,
                VIDEO_FPS,
                VIDEO_SAMPLING_INTERVAL,
                AUDIO_NUM_SAMPLES,
                AUDIO_FPS,
                AUDIO_SAMPLING_INTERVAL,
                AUDIO_TRACE,
               ],
              #force_resave=True,
)

# Prove it worked by plotting the audio from the video :)
import plt
plt.ioff()
plt.plot(mm.get_metrics([AUDIO_TRACE])[AUDIO_TRACE].data)
plt.show()
コード例 #4
0
# x = Dense(100)(x)
# x = BatchNormalization()(x)
# x = Activation('relu')(x)
x = Dense(1)(x)
#####################################################


model = Model(inputs = [u, m], outputs = x)
model.compile(optimizer= SGD(lr = .01, momentum = .9),
              loss = 'mse',
              metrics = ['mse'])              # due to regularization terms

# Train the model
r = model.fit(X_tr, y_tr,
              epochs=epochs,
              batch_size=128,
              validation_data= [X_te, y_te])

# plot losses
plt.plot(r.history['loss'], label="train loss")
plt.plot(r.history['val_loss'], label="test loss")
plt.legend()
plt.show()


# plot mse
plt.plot(r.history['mean_squared_error'], label="train mse")
plt.plot(r.history['val_mean_squared_error'], label="test mse")
plt.legend()
plt.show()
コード例 #5
0
    x, 500, FixedStep(0.1))
points_second, x_second = g_second.gradient_descent(x, 80, FixedStep(1))
points_second_mom, x_second_mom = g_second_mom.gradient_descent(
    x, 500, FixedStep(1))
points_bfgs, x_bfgs = g_bfgs.gradient_descent(x, 500, FixedStep(1))
points_bfgs_mom, x_bfgs_mom = g_bfgs_mom.gradient_descent(x, 500, FixedStep(1))
# points_cr, x_cr = g_cr.gradient_descent(x, 100, FixedStep(-1))
print "Minima achieved at (without momentum) : ", x_first
print "Minima achieved at (with momentum) : ", x_first_mom
print "Minima achieved at for second order (without momentum) : ", x_second
print "Minima achieved at for second order (with momentum) : ", x_second_mom
print "Minima achieved at for bfgs (without momentum) : ", x_bfgs
print "Minima achieved at for bfgs (with momentum) : ", x_bfgs_mom
# print "Minima achieved at for Cubic Regularization (without momentum) : ", x_cr
plot(q,
     q.domain()[0],
     q.domain()[1], [(points_first, "First order"),
                     (points_first_mom, "First order with momentum"),
                     (points_bfgs, "BFGS without momentum"),
                     (points_bfgs_mom, "BFGS with momentum"),
                     (points_second, "Second order"),
                     (points_second_mom, "Second order with momentum")
                     ])  #, (points_cr, "Cubic Regularization") ])
plot_convergence_rate(q, [0, 500], [
    (points_first, "First order"),
    (points_first_mom, "First order with momentum"),
    (points_bfgs, "BFGS without momentum"),
    (points_bfgs_mom, "BFGS with momentum"), (points_second, "Second order"),
    (points_second_mom, "Second order with momentum")
])  #, (points_cr, "Cubic Regularization")])
コード例 #6
0
        ],
        # Other metrics:
        [
            AUDIO_TRACE, TimeMetric, AUDIO, identity,
            ag(AUDIO_SAMPLING_INTERVAL)
        ],
    ]

    mm = VideoMetricsManager(f,
                             NpyStorageInterface(),
                             metrics_definitions,
                             metrics_dict={})
    mm.get_metrics([
        VIDEO_NUM_FRAMES,
        VIDEO_FPS,
        VIDEO_SAMPLING_INTERVAL,
        AUDIO_NUM_SAMPLES,
        AUDIO_FPS,
        AUDIO_SAMPLING_INTERVAL,
        AUDIO_TRACE,
    ],
                   # force_resave=True,
                   )

    # Prove it worked by plotting the audio from the video :)
    import plt

    plt.ioff()
    plt.plot(mm.get_metrics([AUDIO_TRACE])[AUDIO_TRACE].data)
    plt.show()
コード例 #7
0
import joblib
import matplotlib.pyplot import plt
from matrix_analyse_report_anomaly import *

model = joblib.load(model.pkl)

yhat = model.predict(x_test)



plt.plot(x_list, rmses)
plt.ylabel("Errors Values")
file_number = re.findall('\d+', file)
print("the file_number is:", file_number)
plt.title(file_number[0] + ' ' + 'Errors Distribution')
# plt.title(file + ' ' + 'Errors Distribution')
plt.show()
コード例 #8
0
ファイル: usefulP.py プロジェクト: mueller-physics/Chromagnon
def ploty(arrY,
          c=plot_defaultStyle,
          logY=False,
          logX=False,
          hold=None,
          smartTranspose=True,
          logZeroOffset=.01,
          figureNo=None):
    """
    arrY is a "table" of y1,...,yn values
    x-values of 0,1,2,3,4 are used as needed

    if hold is not None:
        if hold is True
            turn plothold on before drawing
        else
            turn plothold off before drawing
    otherwise
        do nothing about current hold setting

    if logY or logX the respective axis is shown in log10 (after applying abs() and adding logZeroOffset)

    if smartTranspose:
        transpose tables if that makes fewer graphs with each more data-points

    if figureNo is not None:
       use that figure instead and switch back to current afterwards
    """
    arrY = N.asarray(arrY)

    if hold is not None:
        plothold(hold, figureNo)

    if len(arrY.shape) == 1 and not logX:
        #if logX:
        #    raise ValueError, 'Cannot use logX=True to plot x="axis-index"'
        #plotxy(arrY) # CHECK
        import plt
        if figureNo is not None:
            _oldActive = plt.interface._active
            #plotFigure(figureNo)  # would Raise !!
            plt.interface._active = plt.interface._figure[figureNo]
            #fig = plt.interface._figure[figureNo]

        if logY:
            arrY = N.log10(abs(arrY) + logZeroOffset)
        plt.plot(arrY, _col(c))
        if figureNo is not None:
            plt.interface._active = _oldActive

    else:
        if len(arrY.shape) == 1:  # !! logX is True
            n = arrY.shape[0]
            x = N.arange(n)
        else:
            if smartTranspose and arrY.shape[0] > arrY.shape[1]:
                arrY = N.transpose(arrY)
            n = arrY.shape[1]
            x = N.arange(n)
        plotxy(x,
               arrY,
               c,
               logY,
               logX,
               smartTranspose=smartTranspose,
               logZeroOffset=logZeroOffset,
               figureNo=figureNo)
コード例 #9
0
ファイル: usefulP.py プロジェクト: mueller-physics/Chromagnon
def plotxy(arr1,
           arr2=None,
           c=plot_defaultStyle,
           logY=False,
           logX=False,
           hold=None,
           smartTranspose=True,
           logZeroOffset=.01,
           figureNo=None):
    """
    arr1 is a "table" of x,y1,...,yn values
    if arr2 is given than arr1 contains only the x values
            and arr2 is "table" y1,...,y2
    if hold is not None:
        if hold is True
            turn plothold on before drawing
        else
            turn plothold off before drawing
    otherwise
        do nothing about current hold setting

    if logY or logX the respective axis is shown in log10 (after applying abs() and adding logZeroOffset)

    if smartTranspose:
        transpose tables if that makes fewer graphs with each more data-points

    if figureNo is not None:
       use that figure instead and switch back to current afterwards
    """
    arr1 = N.asarray(arr1)

    if arr2 is not None:
        if type(arr2) == str:
            c = arr2
            arr2 = None
        else:
            arr2 = N.asarray(arr2)

    if smartTranspose and len(
            arr1.shape) > 1 and arr1.shape[0] > arr1.shape[1]:
        arr1 = N.transpose(arr1)

    if arr2 is None:
        arr2 = arr1[1:]
        arr1 = arr1[:1]
    elif smartTranspose and len(
            arr2.shape) > 1 and arr2.shape[0] > arr2.shape[1]:
        arr2 = N.transpose(arr2)

    # 20040804
    if arr1.dtype.type == N.uint32:
        arr1 = arr1.astype(N.float64)
    if arr2.dtype.type == N.uint32:
        arr2 = arr2.astype(N.float64)

    x = arr1
    arr = arr2

    if logX:
        x = N.log10(abs(x) + logZeroOffset)
    if logY:
        arr = N.log10(abs(arr) + logZeroOffset)

    import plt
    if figureNo is not None:
        _oldActive = plt.interface._active
        #plotFigure(figureNo)  # would Raise !!
        plt.interface._active = plt.interface._figure[figureNo]
        #fig = plt.interface._figure[figureNo]

    if hold is not None:
        plothold(hold)

    if len(arr.shape) == 1:
        plt.plot(x, arr, _col(c))
    else:
        data = []
        for i in range(arr.shape[0]):
            data.extend((x, arr[i], _col(c, overwriteHold=i > 0)))
            plt.plot(*data)

    if figureNo is not None:
        plt.interface._active = _oldActive