Skip to content

Commit

Permalink
Add programming lecture utils
Browse files Browse the repository at this point in the history
  • Loading branch information
CihanSoylu committed Apr 1, 2020
1 parent d082648 commit 1e9b70b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Empty file.
25 changes: 25 additions & 0 deletions programming-lectures/utils/cnn_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import tensorflow as tf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow_datasets as tfds

def load_cats_dogs():
dataset = tfds.load('cats_vs_dogs', split = 'train', shuffle_files=True)

def resize(item):
return tf.image.resize(item['image'], (128,128)), item['label']

dataset = dataset.map(resize)

x_train = []
y_train = []
for item in tfds.as_numpy(dataset):
x_train.append(np.expand_dims(item[0], axis = 0))
y_train.append(item[1])

x_train = np.concatenate(x_train, axis = 0)
y_train = np.array(y_train).reshape(-1,1)

x_train = x_train / 127.5 - 1
return x_train[0:20000], y_train[0:20000], x_train[20000:], y_train[20000:]

0 comments on commit 1e9b70b

Please sign in to comment.