Пример #1
0
    def __init__(self, chunk=1500, img_path_many=None, folder_path=None):
        from keras.models import Model
        self._Model = Model
        from keras.preprocessing import image
        self._image = image
        from keras.applications.xception import Xception as key_model
        self._key_model = key_model
        from keras.applications.xception import preprocess_input, decode_predictions
        self._preprocess_input = preprocess_input
        self._decode_predictions = decode_predictions
        base_model_4 = key_model(weights='imagenet', include_top=False)
        self._base_model_4 = base_model_4
        model = Model(inputs=base_model_4.input, outputs=base_model_4.get_layer(index=-3).output)
        self._model = model

        self.chunk = chunk

        if img_path_many == folder_path == None:
            raise Exception(" choice img_path_many or folder_path")
        elif img_path_many != None:
            self.img_path_many = img_path_many
        elif folder_path != None:
            #             self.folder_path = folder_path
            self.folder_path = folder_path
            self.img_path_many = self._Img_List()
        else:
            raise Exception("at least specify img_path_many or folder_path")

        self.Get_Target()
Пример #2
0
from database import DATABASE
import pickle
import faiss

import numpy as np
from keras.models import Model
from keras.preprocessing import image
from keras.applications.xception import Xception as key_model
from keras.applications.xception import preprocess_input, decode_predictions

base_model_4 = key_model(weights='imagenet', include_top=False)
model = Model(inputs=base_model_4.input,
              outputs=base_model_4.get_layer(index=-3).output)

reduced_database = DATABASE()
reduced_database.database_chose("bar")
reduced_database.collection_chose("raw_vector01_redu")

data_from_database = reduced_database.get_data(movie_name=0).astype("float32")
compare_data = data_from_database[:, :-2]
compare_target = data_from_database[:, -2:]

img_path = "/data/bar03/screenshot01/0_160.jpg"


def Jpg_To_Vector(img_path):
    if isinstance(img_path, list):
        img_path = img_path[0]

    img = image.load_img(img_path, target_size=(299, 299))
    x = image.img_to_array(img)