Exemple #1
0
def save_specific(to_save, full=False, gray=False):
    prep = Preprocessor(crop_style=1, gray=gray, should_normalize=False)
    for i in to_save:
        if full:
            save_full(i, trial[i])
        else:
            ball, car = prep.process_frame(trial[i])
            save(i, ball, car, gray)
def generateSummary(PATH, SIZE):
    p = Preprocessor(PATH, 1).parse()
    scorer = SentenceScoreCalculator(p)

    summary = sorted(
        sorted(range(p.sCount), key=lambda s: scorer.rank(s),
               reverse=True)[0:SIZE])

    return map(lambda s: p.sentences[s], summary)
Exemple #3
0
def init():
    prep = Preprocessor()
    trial = np.load('data/trial_{}.npy'.format(1))
    ball_crop = prep.get_ball_batch(trial).astype(np.float32)

    global ball_mean, ball_mse_mean, ball_mse_std

    ball_mean = np.mean(ball_crop, axis=0)
    mses = np.mean(np.square(ball_crop - ball_mean), axis=(1, 2, 3))
    ball_mse_mean = mses.mean()
    ball_mse_std = mses.std()
Exemple #4
0
def main():
    prep = Preprocessor(crop_style=1, should_normalize=False)
    for i, frame in enumerate(trial):
        print(i)
        ball, car = prep.get_ball_and_car(frame)
        show(car)
        cv2.waitKey(0)

        keys = key_check()
        while not (len(keys) == 1 and ('0' in keys or '1' in keys)):
            time.sleep(0.1)
            keys = key_check()

        if '1' in keys:
            save(i, ball, car)

        cv2.destroyAllWindows()
    def __init__(
        self,
        crop_style=0,
        gray=False,
        frame_time=1 / 8,
        read_only=False,
        normalize=True,
        buffer_size=3,
        field='champions',
        reward_func=lambda x: 1,
    ):
        self.field = field
        self.crop_style = crop_style
        if crop_style is None:
            self.prep = None
        else:
            self.prep = Preprocessor(crop_style,
                                     gray=gray,
                                     should_normalize=normalize,
                                     field=field)

            if gray:
                self.ball_obs_dims = self.prep.ball_dims + (buffer_size, )
                self.car_obs_dims = self.prep.car_dims + (buffer_size, )
            else:
                self.ball_obs_dims = self.prep.ball_dims + (3 * buffer_size, )
                self.car_obs_dims = self.prep.car_dims + (3 * buffer_size, )

        self.bboxes = (get_screen_bbox(), )
        self.next_frame = time.time()
        self.read_only = read_only
        self.frame_time = frame_time
        self.get_reward = reward_func

        self.gray = gray
        self.frame_buffer = deque(maxlen=buffer_size)  # Save last three frames

        self.frame_times = []
        self.obs_times = []
def generateSummary(PATH, NGRAMS, CLUSTERS, TYPE):
    # Preprocessing and Term Selection
    p = Preprocessor(PATH, NGRAMS).parse()
    counter = WordCounter(p.sCount).count(p.processed)

    # Term weighting and feature selection
    features = buildFeatures(p, counter, TYPE)

    # Sentence clustering
    kmeans = KMeans(
        n_clusters=CLUSTERS,
        #n_jobs=4,
        precompute_distances=True,
        init="k-means++",
        random_state=500,
        tol=1e-10,
        copy_x=True)
    kmeans.fit(features)

    #Sentence selection
    summary = sentenceSelect(kmeans, p, features)

    return map(lambda s: p.sentences[s], sorted(summary))
    help="Enables the stopwords' filter (using nltk's stopwords list).",
    action="store_true")
parser.add_argument("-t",
                    help="Enables the stopwords' filter (using pos tag).",
                    action="store_true")
parser.add_argument("-u", help="Enables the url filter.", action="store_true")
parser.add_argument("-n", help="Enables the not adapter.", action="store_true")
args = parser.parse_args()

######### Object creation

# timer used for timing
timer = Timer()

# a preprocessor
preprocess = Preprocessor()

print ""
print ""
# Classifier selection
if (args.classifier == 'svm'):
    from classifier.svmClassifier import SVMClassifier
    print "Classifier:	SVM Classifier."
    classifier = SVMClassifier()
else:
    if (args.classifier == 'bayes'):
        from classifier.bayesianClassifier import BayesianClassifier
        print "Classifier:	Bayesian Classifier."
        classifier = BayesianClassifier()
    else:
        from classifier.shortTextClassifier import ShortTextClassifier
    #         print(i, mses[index])
    #         show(trial[index])
    #         # print(i, mses[i])
    #         # show(trial[i])

    def show_gray(img):
        cv2.imshow('cropped', img)
        cv2.waitKey(0)
        cv2.destroyAllWindows()

    gray_minframe = gray_mses.argmin()
    gray_maxframe = gray_mses.argmax()
    show_gray(gray_crop[gray_minframe].reshape(gray_mean.shape))
    show_gray(gray_mean)
    show_gray(gray_crop[gray_maxframe].reshape(gray_mean.shape))
    show_gray(gray_mean)


if __name__ == '__main__':
    prep = Preprocessor(crop_style=1)
    # 13 trials
    for trial_num in range(7):
        print('Displaying trial {}'.format(trial_num))
        trial = np.load('data/champions/trial_{}.npy'.format(trial_num))
        show(trial[0])
        ball, car = prep.get_ball_and_car(trial[0])
        show(ball)
        show(car)

    # ball_crop(trial)