This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ['\n', ' ', '!', "'", '(', ')', '*', ',', '-', '.', '0', | |
| '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', | |
| '?', '\\', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', | |
| 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', | |
| 'u', 'v', 'w', 'x', 'y', 'z', '{', '}'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| to_remove = {'\n', '\\','{', '}'} | |
| new_data = ''.join(char for char in data if char not in to_remove) | |
| unique_chars = sorted(list(set(new_data))) | |
| ''' | |
| [' ', '!',"'",'(', ')', '*', ',', '-', '.', '0', '1', '2', '3', | |
| '4', '5', '6', '7', '8', '9', ':', ';', '?', 'a', 'b', 'c', 'd', | |
| 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with open('bible.txt.rtf', encoding = 'utf-8', errors = 'ignore') as f: | |
| data = f.read() | |
| data = data.lower() | |
| print(data[500:550], data[0:65]) | |
| ''' | |
| ('ed the heaven and the earth.\\\n\\\n1:2 and the earth ', | |
| '{\\rtf1\\ansi\\ansicpg1252\\cocoartf1671\\cocoasubrtf500\n{\\fonttbl\\f0\\') | |
| ''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from keras.callbacks import ModelCheckpoint | |
| from keras.callbacks import CSVLogger | |
| from keras.callbacks import EarlyStopping | |
| from keras.optimizers import Adam | |
| import model | |
| NO_OF_TRAINING_IMAGES = len(os.listdir('/your_data/train_frames/train/')) | |
| NO_OF_VAL_IMAGES = len(os.listdir('/your_data/val_frames/val/')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| def data_gen(img_folder, mask_folder, batch_size): | |
| c = 0 | |
| n = os.listdir(img_folder) #List of training images | |
| random.shuffle(n) | |
| while (True): | |
| img = np.zeros((batch_size, 512, 512, 3)).astype('float') | |
| mask = np.zeros((batch_size, 512, 512, 1)).astype('float') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| train_image_generator = train_datagen.flow_from_directory( | |
| 'data/train_frames/train', | |
| batch_size = #NORMALLY 4/8/16/32) | |
| train_mask_generator = train_datagen.flow_from_directory( | |
| 'data/train_masks/train', | |
| batch_size = #NORMALLY 4/8/16/32) | |
| val_image_generator = val_datagen.flow_from_directory( | |
| 'data/val_frames/val', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from keras.preprocessing.image import ImageDataGenerator | |
| train_datagen = ImageDataGenerator( | |
| rescale=1./255, | |
| shear_range=0.2, | |
| zoom_range=0.2, | |
| horizontal_flip=True) | |
| val_datagen = ImageDataGenerator(rescale=1./255) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import random | |
| import re | |
| from PIL import Image | |
| DATA_PATH = '/path/to/your/data_dir' | |
| FRAME_PATH = DATA_PATH+'/frames' | |
| MASK_PATH = DATA_PATH+'/masks' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| subjects = ['English', 'Physics', 'Math', 'Chemistry', 'Economics'] | |
| grades = [85, 91, 90, 90, 95] | |
| marks = {} | |
| performance = zip(subjects, grades) | |
| print performance #-> [('English', 85), ('Physics', 91), ('Math', 90), ('Chemistry', 90), ('Economics', 95)] | |
| marks = dict(performance) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| sentence = "There will be a full moon tonight. It’s going to be beautiful!" | |
| vowel_count = {} | |
| vowels = ['a', 'e', 'i', 'o', 'u'] | |
| for char in sentence: | |
| if char in vowels: | |
| vowel_count[char] = vowel_count.get(char, 0) + 1 |
NewerOlder