예제 #1
0
def load_images_only(image_paths):
    images = []
    print("Images:")
    for i, image_path in enumerate(image_paths):
        print("\t#{}: {}".format(i, image_path))
        image, raw_image = preprocess(image_path)
        images.append(image)
    return images
예제 #2
0
import gym
from main import stack_frames, preprocess
from model import PolicyGradientAgent

agent = PolicyGradientAgent(learning_rate=0.001,
                            discount_factor=0.9,
                            num_actions=6,
                            chkpt_dir='tmp/checkpoint')
agent.load_checkpoint()

env = gym.make('SpaceInvaders-v0')
observation = env.reset()
observation = preprocess(observation)

stack_size = 4
stacked_frames = None
stacked_frames = stack_frames(stacked_frames, observation, stack_size)

done = False
while not done:
    env.render()

    action = agent.choose_action(stacked_frames)
    obseravtion, reward, done, info = env.step(action)

    observation = preprocess(observation)
    stacked_frames = stack_frames(stacked_frames, observation, stack_size)

env.close()
예제 #3
0
    def display_graph(self):
        self.algorithm = self.combobox_algs.get()
        self.mode = self.combobox_types.get()
        print(self.mode)
        print(self.algorithm)


        if self.mode == "Google":
            self.file_path = "googl.us.txt"
        elif self.mode == "Apple":
            self.file_path = "aapl.us.txt"
        elif self.mode == "Amazon":
            self.file_path = "amzn.us.txt"
        elif self.mode == "Coca Cola":
            self.file_path = "ko.us.txt"


        # df = load_file(self.file_path)

        df = pd.read_csv(self.file_path)

        # if self.algorithm == "SVM":
        #     print("Svm izabran")
        #     # self.y_train, self.y_val, self.y_predict = svm_prediction(df)
        #
        #     new_df = preprocess(load_file(self.file_path))
        #     x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
        #     self.y_predict = svm_prediction(df, x_train, y_train, x_valid, y_valid)
        #     self.y_train = y_train
        #     self.y_val = y_valid



        if self.algorithm == "Moving average":
            print("MA izabran")
            #NISAM TESTIRAO MA, TREBA MODIFIKOVATI

            new_df = preprocess(load_file(self.file_path))
            x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
            self.y_predict = predict_ma(df)
            self.y_train = y_train
            self.y_val = y_valid

        elif self.algorithm == "KNN":
            print("KNN izabran")
            df = load_file(self.file_path)
            new_df = preprocess(df)
            x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
            self.y_predict = knn_predict(x_train, y_train, x_valid)
            self.y_train = y_train
            self.y_val = y_valid

            plt.plot(self.y_train)
            plt.plot(self.y_val)
            plt.plot(self.y_predict)
            plt.show()

            # plot_graph(self.train, self.valid, self.y_predict)
        elif self.algorithm == "Auto Arima":
            print("Auto Arima izabran")
            # UBACI OVDE POZIV AUTO ARIMA METODE
            df = load_file(self.file_path)
            new_df = preprocess(df)
            x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
            self.y_predict = auto_arima_predict(df)
            self.y_train = y_train
            self.y_val = y_valid

        elif self.algorithm == "Linear Regression":
            print("Linear Regression izabran")
            # UBACI OVDE POZIV LINEAR REGRESSION
            df = load_file(self.file_path)
            new_df = preprocess(df)
            x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
            self.y_predict = linearregression.run_regression(x_train, y_train, x_valid, y_valid)
            self.y_train = y_train
            self.y_val = y_valid

            plt.plot(self.y_train)
            plt.plot(self.y_val)
            plt.plot(self.y_predict)
            plt.show()
        elif self.algorithm == "Prophet":
            print("Prophet")
            df = load_file(self.file_path)
            new_df = preprocess(df)
            x_train, y_train, x_valid, y_valid, self.train, self.valid = train_valid_split(new_df)
            self.y_predict = prophet_predict(self.train, self.valid)
            self.y_train = y_train
            self.y_val = y_valid

            plt.plot(self.y_train)
            plt.plot(self.y_val)
            plt.plot(self.y_predict)
            plt.show()


        print(self.y_predict)

        print("Zavrsio obucavanje i predikciju")


        p1 = figure(x_axis_type="datetime", title="Stock Closing Prices")
        p1.grid.grid_line_alpha = 0.3
        p1.xaxis.axis_label = 'Date'
        p1.yaxis.axis_label = 'Price'

        plot_dates = df['Date']
        print(self.valid)
        plot_dates = plot_dates[-len(self.y_predict):]
        p1.line(plot_dates, self.valid['Close'], color='#A6CEE3', legend=self.mode)
        p1.line(plot_dates, self.y_predict, color='#B2DF8A', legend="Predicted "+self.mode)

        output_file("stocks.html", title="Stocks prediction")

        show(gridplot([[p1]], plot_width=500, plot_height=500))
예제 #4
0
파일: test.py 프로젝트: pmoreirac/DSE
 def test_preprocess(self):
     doc = 'Preprocess this string and output array of tokens'
     assert preprocess(doc) == [
         'preprocess', 'string', 'output', 'array', 'token'
     ]
예제 #5
0
from main import preprocess, extract_contours, cleanAndRead

windowname = "Live Video"

cap = cv2.VideoCapture(0)
t = 3
if cap.isOpened():
    ret, frame = cap.read()
else:
    ret = False
while ret:

    ret, img = cap.read()
    #time.sleep(t)
    cv2.imshow(windowname, img)
    print("DETECTING PLATE . . .")
    #img = cv2.imread("testData/Final.JPG")
    threshold_img = preprocess(img)
    contours = extract_contours(threshold_img)
    #if len(contours)!=0:
    #print len(contours) #Test
    # cv2.drawContours(img, contours, -1, (0,255,0), 1)
    # cv2.imshow("Contours",img)
    # cv2.waitKey(0)

    cleanAndRead(img, contours)
    if cv2.waitKey(1) == 27:
        break
cv2.destroyAllWindows()
cap.release()
예제 #6
0
modelctrl = 1  #1 --> Ada, 0 --> SVM
###################
if datactrl == "PC1":
    dataset_path = 'MDP csv/PC01.csv'
if datactrl == "PC2":
    dataset_path = 'MDP csv/PC02.csv'
if datactrl == "PC3":
    dataset_path = 'MDP csv/PC03.csv'
if datactrl == "PC4":
    dataset_path = 'MDP csv/PC04.csv'
if datactrl == "PC5":
    dataset_path = 'MDP csv/PC05.csv'
print("dataset_path-->", dataset_path)
return dataset_path

feature_data, target_data = preprocess(dataset_path, datactrl)
print('feature_data')
print(feature_data)
print(feature_data.shape)

print('target_data')
print(target_data)
print(target_data.shape)

discretize_data = discretize(feature_data)
print('\n')
print("*** Discretize Data ***")
print(discretize_data)
print(discretize_data.shape)

concat_data = 0