Exemple #1
0
def train_model_CNN_LSTM_New(files_original, files_fake):
    files = []
    files.extend(files_original)
    files.extend(files_fake)
    np.random.shuffle(files)
    CNN_LSTM_model = getCustomCNNLSTMModel(number_of_faces, height, width, 3)
    for file in files:
        frames = get_frames(file, startingPoint=0)
        faces = get_faces(frames,
                          height=height,
                          width=width,
                          number_of_faces=number_of_faces)
        faces = np.asarray(faces)
        faces = np.array(faces)
        if (len(faces) != number_of_faces):
            continue
        if (file in files_original):
            label = [0, 1]
        if (file in files_fake):
            label = [1, 0]
        input_for_LSTM = faces.reshape(1, number_of_faces, height, width, 3)
        labels = []
        labels.append(label)
        y_train = np.asarray(labels)
        CNN_LSTM_model.fit(input_for_LSTM, y_train, epochs=20, verbose=1)
        del faces
        del input_for_LSTM
        del frames

    CNN_LSTM_model.save('CNN_New_lstmModel.h5')
Exemple #2
0
def test_model_CNN_Lstm(model_name, files):
    model = load_model(model_name)
    for file in files:
        print("File")
        frames = get_frames(file, number_of_frames=-1, startingPoint=0)
        faces = get_faces(frames,
                          height=height,
                          width=width,
                          number_of_faces=number_of_faces)
        # if(len(faces)!=number_of_faces):
        #     print("File: " + str(file))
        #     print("No Result Found\n")
        #     continue;
        # else:
        #     tempFaces.extend(faces)
        #     count = count+1;

        testFaces = np.asarray(faces)
        input_for_LSTM = testFaces.reshape(1, number_of_faces, height, width,
                                           3)
        print("Shape for testing:", input_for_LSTM.shape)
        y_test_result = model.predict(input_for_LSTM)
        print("\n\n")
        print("Result: ")
        print(y_test_result)
        print("\n")
Exemple #3
0
def get_faces_local_for_CNN(files_original, files_fake):
    np.set_printoptions(threshold=sys.maxsize)
    tempFaces = []

    labels = []

    for original_file in files_original:
        frames = get_frames(original_file, startingPoint=0)
        faces = get_faces(frames,
                          height=height,
                          width=width,
                          number_of_faces=number_of_faces)
        if (len(faces) == number_of_faces):
            tempFaces.extend(faces)
            for face in faces:
                labels.append([0, 1])

        del frames
        del faces

    facesCorrect = np.asarray(tempFaces)
    tempFaces = []
    for fake_file in files_fake:
        frames = get_frames(fake_file, startingPoint=0)
        faces = get_faces(frames,
                          height=height,
                          width=width,
                          number_of_faces=number_of_faces)
        if (len(faces) == number_of_faces):
            tempFaces.extend(faces)
            for face in faces:
                labels.append([1, 0])
        del frames
        del faces

    facesIncorrect = np.asarray(tempFaces)
    count_incorrect = len(facesIncorrect)
    count_correct = len(facesCorrect)
    print(facesIncorrect.shape)
    x_train = np.concatenate((facesCorrect, facesIncorrect))
    return x_train, count_incorrect, count_correct, labels
Exemple #4
0
def test_model(files):
    model = load_model('classification_CNN.h5')
    for file in files:
        frames = get_frames(file, number_of_frames=40, startingPoint=0)
        tempFaces = (get_faces(frames, height=height, width=width))
        testFaces = np.asarray(tempFaces)
        testFaces_shape = testFaces.shape
        testFaces = testFaces.reshape(testFaces_shape[0], testFaces_shape[1],
                                      testFaces_shape[2], 1)
        print(testFaces[0].shape)
        #testFaces = np.concatenate(testFaces)
        print(testFaces.shape)
        y_test_result = model.predict(testFaces)
        count_fake = 0
        count_positive = 0
        count_clear_fake = 0
        count_clear_positive = 0

        for frame_result in y_test_result:

            if (frame_result[0] - frame_result[1] >= 0.3):
                count_clear_positive = count_clear_positive + 1
            elif (frame_result[0] - frame_result[1] > 0):
                count_positive = count_positive + 1
            elif (frame_result[1] - frame_result[0] >= 0.3):
                count_clear_fake = count_clear_fake + 1
            elif (frame_result[1] - frame_result[0] > 0):
                count_fake = count_fake + 1
            else:
                count_doubt = count_doubt + 1

        print("File: " + file)
        print("count_clear positive:" + str(count_clear_positive))
        print("count_positive: " + str(count_positive))
        print("count_fake: " + str(count_fake))
        print("count_clear_fake: " + str(count_clear_fake))

        print("\n")
        del frames
height = 320
width=320
number_of_faces=40

def get_all_files(folder):
    filepaths = [os.path.join(folder, f) for f in os.listdir(folder)]
    return filepaths


files_fake = get_all_files('../../manipulated_sequences/Deepfakes/raw/videos/')
files_original = get_all_files('../../original_sequences/youtube/raw/videos/')


for file in files_fake:
    frames = get_frames(file, startingPoint=0)
    faces = get_faces(frames, height=height, width=width, number_of_faces=1)
    if(len(faces)>0):
        photo = cv.Canny(faces[0],0,10)
        fig, ax = plt.subplots(1, 1, figsize=(15, 15))
        ax.xaxis.set_visible(False)
        ax.yaxis.set_visible(False)
        plt.grid(False)
        ax.imshow(photo)
        plt.show()




# fig, ax = plt.subplots(nrows=2, ncols=3, figsize=(8, 5),
#                        sharex=True, sharey=True)
from face_detect_util.get_face import get_frames, get_faces, get_cropped_images

height = 320
width = 320
number_of_faces = 2


def get_all_files(folder):
    filepaths = [os.path.join(folder, f) for f in os.listdir(folder)]
    return filepaths


files_fake = get_all_files('../../manipulated_sequences/Deepfakes/raw/videos/')
files_original = get_all_files('../../original_sequences/youtube/raw/videos/')

frames = get_frames(files_fake[2], startingPoint=0)
faces = get_faces(frames,
                  height=height,
                  width=width,
                  number_of_faces=number_of_faces)
original_true = img_as_float(faces[0])

frames = get_frames(files_original[0], startingPoint=0)
faces = get_faces(frames,
                  height=height,
                  width=width,
                  number_of_faces=number_of_faces)
original_false = img_as_float(faces[0])

sigma = 0.12
noisy_true = random_noise(original_true, var=sigma**2)
height = 299
width = 299
number_of_faces = 40


def get_all_files(folder):
    filepaths = [os.path.join(folder, f) for f in os.listdir(folder)]
    return filepaths


files_fake = get_all_files('../manipulated_sequences/Deepfakes/raw/videos/')
files_original = get_all_files('../original_sequences/youtube/raw/videos/')

for file_fake, file_original in zip(files_fake, files_original):
    frames = get_frames(file_fake, startingPoint=0)
    faces = get_faces(frames,
                      height=height,
                      width=width,
                      number_of_faces=number_of_faces)
    if (len(faces) == number_of_faces):
        for face in faces:
            fig, ax = plt.subplots(1, 1, figsize=(15, 15))
            ax.imshow(face)
            ax.xaxis.set_visible(False)
            ax.yaxis.set_visible(False)
            ax.title.set_text(f"FRAME 0: {file_fake.split('/')[-1]}")
            plt.grid(False)
            plt.show()

    frames = get_frames(file_original, startingPoint=0)