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
| def modelFitGenerator(fitModel): | |
| num_train_samples = sum([len(files) for r, d, files in os.walk(train_data_dir)]) | |
| num_valid_samples = sum([len(files) for r, d, files in os.walk(validation_data_dir)]) | |
| num_train_steps = math.floor(num_train_samples/batch_size) | |
| num_valid_steps = math.floor(num_valid_samples/batch_size) | |
| train_datagen = ImageDataGenerator( | |
| rotation_range=90, |
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
| def saveCoreMLModel(kerasModel): | |
| coreml_model = coremltools.converters.keras.convert(kerasModel, | |
| input_names=['input'], | |
| output_names=['probs'], | |
| image_input_names='input', | |
| predicted_feature_name='predictedMoney', | |
| class_labels = 'drive/Resnet/labels.txt') | |
| coreml_model.save('resnet50custom.mlmodel') | |
| print('CoreML model saved') |
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 CreateML | |
| import Foundation | |
| // 1. CSV'den veri alma | |
| var data = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/ozgur/Documents/CreateMLFiles/dataset/bitmojiReviews.csv")) |
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
| let parsingOptions = MLDataTable.ParsingOptions(containsHeader: true, delimiter: ",", comment: "", escape: "", doubleQuote: false, quote: "", skipInitialSpaces: false, missingValues: [], lineTerminator: "\r", selectColumns:["author","rating","review"], maxRows: nil, skipRows: 0) | |
| var table = try MLDataTable(contentsOf: URL(fileURLWithPath: "/Users/ozgur/Documents/CreateMLFiles/dataset/bitmojiReviews.csv"), options: parsingOptions) |
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
| let newColumn = data.map { row -> Double in | |
| guard let deger1 = row["deg1"]?.intValue, | |
| let deger2 = row["deg2"]?.intValue, | |
| let deger3 = row["deg3"]?.doubleValue | |
| else { | |
| fatalError("Missing or invalid columns in row.") | |
| } | |
| let sum = Double(deger1)+Double(deger2)+deger3 | |
| return sum | |
| } |
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
| let data: [String: MLDataValueConvertible] = [ | |
| "Title": ["Alice in Wonderland", "Hamlet", "Treasure Island", "Peter Pan"], | |
| "Author": ["Lewis Carroll", "William Shakespeare", "Robert L. Stevenson", "J. M. Barrie"], | |
| "Pages": [124, 98, 280, 94], | |
| ] | |
| var bookTable = try MLDataTable(dictionary: data) |
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
| let pagesColumn = MLDataColumn([124, 98, 280, 94]) | |
| bookTable.addColumn(pagesColumn, named: "Pages") |
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
| let newColumn = data.map { row -> String in | |
| guard | |
| let average = row["deg3"]?.doubleValue | |
| else { | |
| fatalError("Missing or invalid columns in row.") | |
| } | |
| var sentiment = "negative" | |
| if average < 0 |
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 NaturalLanguage | |
| let text = "All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood." | |
| let tokenizer = NLTokenizer(unit: .word) | |
| tokenizer.string = text | |
| //let tokenArray = tokenizer.tokens(for: strRange) | |
| tokenizer.enumerateTokens(in: text.startIndex..<text.endIndex) { tokenRange, _ in | |
| print(text[tokenRange]) | |
| return true |
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 NaturalLanguage | |
| let recognizer = NLLanguageRecognizer() | |
| recognizer.processString("oduncu") | |
| let lang = recognizer.dominantLanguage | |
| let hypotheses = recognizer.languageHypotheses(withMaximum:2) | |
| //convenience method: NLLanguageRecognizer.dominantLanguage(for: "oduncu") |