def main(): # create_date_set(lambda x: np.sin(x), np.linspace(0, 10, 10, endpoint=True), "sin.txt") # x, y = read_data("sin.txt") # a, b, c, d = spline.get_coefficients(x, y) # show(x, y, b, c, d, lambda t: np.sin(t)) func_num = utils.choose_from_map(functions) section = utils.read_section("Введите интервал, используя разделитель ;", ";") n = utils.read_int( 0, 100, "Укажите количество узлов для вычисления уравнения сплайнов") x = np.linspace(section[0], section[1], n, endpoint=True) y = functions[func_num][1](x) a, b, c, d = spline.get_coefficients(x, y) show(x, y, b, c, d, functions[func_num][1])
import numpy as np from keras.models import load_model import cv2 import os from utils import file_generator from utils import read_section properties = read_section("part4.ini", "part4") model_dir = properties["model.save.dir"] model_file = properties["model.save.name"] faces_out_dir = properties["real.faces.out.dir"] not_faces_out_dir = properties["not.real.faces.out.dir"] src_dir = properties["faces.dir"] model = load_model(model_dir + model_file) def main(): out_dir = [not_faces_out_dir, faces_out_dir] for file_name in file_generator(src_dir): try: img = cv2.imread(file_name) img = img.reshape(1, img.shape[0], img.shape[1], img.shape[2]) a = model.predict(img) os.rename(file_name, out_dir[int(a[0][0])] + file_name[len(src_dir):]) except Exception as e: print(str(e))
import numpy as np import os import cv2 from utils import read_section properties = read_section("part3.ini", "part3") input_dir = properties["dataset.dir"] input_X = input_dir + properties["dataset.file.name.x"] input_y = input_dir + properties["dataset.file.name.y"] def load_data(): X = np.load(input_X) y = np.load(input_y) size = y.shape[0] indices = np.random.permutation(size) eighty = (int)(size*80/100) training_idx, test_idx = indices[:eighty], indices[eighty:] training_X, test_X = X[training_idx,:,:], X[test_idx,:,:] training_y, test_y = y[training_idx], y[test_idx] return (training_X, test_X), (training_y, test_y)
import numpy as np import os import cv2 from utils import read_section from utils import file_generator properties = read_section("part2.ini", "part2") faces_dir = properties["input.images.faces"] other_dir = properties["input.images.other"] extension = properties["images.extension"] image_height = int(properties["face.size.height"]) image_width = int(properties["face.size.width"]) output_dir = properties["output.dataset.dir"] output_X = output_dir + properties["dataset.file.name.x"] output_y = output_dir + properties["dataset.file.name.y"] def read_dir(ar, y, dir, cur_class): a = 0 for filename in file_generator(dir): try: img = cv2.imread(filename) if(ar.shape[0] == 1 and a == 0): ar[0,:,:,:] = img a = 1 else: tmp = np.zeros((1,image_height,image_width,3)) tmp[0,:,:,:] = img ar = np.concatenate((ar, tmp), axis=0) y = np.append(y, cur_class) except Exception as e:
import streamingDataset as sd import numpy as np np.random.seed(2808) from keras.models import Sequential from keras.layers import Dense, Dropout, Flatten from keras.layers import Conv2D, MaxPooling2D from keras.utils import np_utils from keras import backend as K from utils import read_section from keras.optimizers import Adam properties = read_section("part5.ini", "part5") dirs = [properties["real.faces.dir"], properties["not.real.faces.dir"]] classes = [1, 0] dataset = sd.StreamingDataset(dirs, classes) model_dir = properties["model.save.dir"] model_file = properties["model.save.name"] ''' (X_train, X_test), (y_train, y_test) = load_data() if K.image_data_format() == 'channels_first': X_train = X_train.reshape(X_train.shape[0], X_train.shape[3], X_train.shape[1], X_train.shape[2]) X_test = X_test.reshape(X_test.shape[0], X_test.shape[3], X_test.shape[1], X_test.shape[2]) input_shape = (X_train.shape[3], X_train.shape[1], X_train.shape[2]) else: input_shape = (X_train.shape[1], X_train.shape[2], X_train.shape[3]) X_train = X_train.astype('float32') X_test = X_test.astype('float32')
if x == 1: return 0 return (x**3 - x**2) / (x - 1) integral = u'\u222b' integrals = ((integral + " x^2 dx", lambda x: x**2), (integral + " x^3 dx", lambda x: x**3), (integral + " sin(x) dx", lambda x: np.sin(x)), (integral + " x^3-x^2+3 dx", lambda x: x**3 - x**2 + 3), (integral + " 1/x dx", lambda x: one_for_x(x)), (integral + " ln(x) dx", lambda x: lnx(x)), (integral + " sin(x)/x dx", lambda x: sinx_x(x)), (integral + " (x^3-x^2)/(x-1) dx", lambda x: x3_x2_div_x1(x))) print("Выберите какой интеграл посчитать") integral_num = ut.choose_from_map(integrals) section = ut.read_section("Введите интервал используя разделитель ;", ";") epsilon = ut.read_float(0, 100, "Введите эпсилон") try: result, inaccuracy, new_n = integral_solve_symp.solve_with_eps_sympson( section[0], section[1], 5, integrals[integral_num][1], epsilon) print("Результат работы метода Симпсона: " + str(result)) print("Погрешность вычисления метода Симпсона: " + str(inaccuracy)) print("n: " + str(new_n)) except ValueError as e: print( "Произошла ошибка при вычислении значения функции на промежутке, Adios" ) sys.exit()
for i in range(len(x)): plt.scatter(x[i], y[i]) for point in points: plt.scatter(point[0], point[1]) plt.plot(fun_x, spline_y, label='Вычисленная функция') plt.grid() plt.legend() plt.hlines(0, x[0], x[len(x) - 1], color="black") if x[0] * x[1] <= 0: plt.vlines(0, plt.ylim()[0], plt.ylim()[1], color="black") plt.show() if __name__ == '__main__': func_num = utils.choose_from_map(functions) x0, x_last = utils.read_section("Введите промежуток используя ;", ";") inaccuracy = utils.read_float( 0, 100, "Введите точность, с которой будет вычислено значение") y0 = utils.read_float(-1000.0, 1000.0, "Введите значение у0 в левой границе отрезка") try: c_integral = functions_c[func_num][1](x0, y0) x, y = runge.calculate_data_set(x0, y0, x_last, functions[func_num][1], functions_integral[func_num][1], c_integral, 0.1) # print(x) # print(y) a, b, c, d = spline.get_coefficients(x, y) show(x, y, b, c, d, functions_integral[func_num][1], c_integral) except Exception: print(