def Load_pickle(): pickle = Pickle() label = pickle.load_label_pickle("label_pickle") feature = pickle.load_feature_pickle("feature_pickle") return feature,label
def __init__(self, thread): logging.basicConfig(filename='logging.log', level=logging.DEBUG, format='%(asctime)s %(message)s') if thread: self.my_lock = threading.Lock() self.my_semaphore = threading.Semaphore(SEMAPHORE_MAX_NUM) else: self.my_lock = multiprocessing.Lock() self.my_semaphore = multiprocessing.Semaphore(SEMAPHORE_MAX_NUM) Pickle.__init__(self)
def delete_value(self, key): logging.info("deleting from database") self.my_lock.acquire() for user in range(SEMAPHORE_MAX_NUM): self.my_semaphore.acquire() Pickle.delete_value(self, key) for user in range(SEMAPHORE_MAX_NUM): self.my_semaphore.release() self.my_lock.release() logging.info("finished deleting from database")
def set_value(self, key, val): logging.info("writing to database") self.my_lock.acquire() for i in range(SEMAPHORE_MAX_NUM): self.my_semaphore.acquire() Pickle.set_value(self, key, val) for i in range(SEMAPHORE_MAX_NUM): self.my_semaphore.release() self.my_lock.release() logging.info("finished writing to database")
def get_value(self, key): logging.info("reading from database") self.my_semaphore.acquire() val = Pickle.get_value(self, key) self.my_semaphore.release() logging.info("finished reading from database") return val
def Save_pickle(): dataset = Dataset() save = dataset.read_training_dataset("train") label, feature = dataset.label_feature(save,"Emotion","Pixels") pickle = Pickle() pickle.save_label_pickle(label) pickle.save_feature_pickle(feature)
metrics=['accuracy']) epochs = 1000 batch_size = 40 model.fit(feature, label, batch_size=batch_size, epochs=epochs, validation_split=0.2, callbacks=callbacks) if __name__ == "__main__": pickle = Pickle() ## loading dataset label = pickle.load_label_pickle("label_pickle") feature = pickle.load_feature_pickle("feature_pickle") # converting numbers btw 0-1 and converting format to float50 for count in range(len(feature)): feature[count] = feature[count] / 255.0 feature[count] = feature[count].astype("float32") ## convertin feature and label to numpy array feature = numpy.array(feature).reshape(-1, 48, 48, 1) label = numpy.array(label) cnn_model(feature, label)