{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import tensorflow as tf\nprint(\"Num GPUs Available: \", len(tf.config.experimental.list_physical_devices('GPU')))","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:32.776400Z","iopub.execute_input":"2023-01-16T22:26:32.776914Z","iopub.status.idle":"2023-01-16T22:26:32.784420Z","shell.execute_reply.started":"2023-01-16T22:26:32.776876Z","shell.execute_reply":"2023-01-16T22:26:32.782680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.debugging.set_log_device_placement(True)\n\n# Create some tensors\na = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])\nb = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])\nc = tf.matmul(a, b)\n\nprint(c)","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:32.787003Z","iopub.execute_input":"2023-01-16T22:26:32.787422Z","iopub.status.idle":"2023-01-16T22:26:32.803563Z","shell.execute_reply.started":"2023-01-16T22:26:32.787383Z","shell.execute_reply":"2023-01-16T22:26:32.802163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Initialising Hyper Parameters\n\n#Uncomment one of the two below lines. For some reason, on some computers the first one works, while on others the second.\nfrom tensorflow.keras.optimizers import Adam\n#from keras.optimizers import adam\nimport tensorflow as tf\n\nimport numpy as np\nimport keras\n\nnp.random.seed(10)  #for consistency of random numbers and our images\n\nnoise_dim = 100  # input dimension of random vector - the vector that goes into the generator\n\nbatch_size = 64   #How many images do we want to include in each batch\nsteps_per_epoch = 3750  #How many steps do we want to take per iteration of our training set (number of batches)\nepochs = 10      #How many iterations of our training set do we want to do.\n\n#change the below values to the dimensions of your image. The channels number refers to the number of colors\nimg_rows, img_cols, channels = 128, 128, 3\n\n#These are the recommended values for the optimizer\noptimizer = Adam(0.0002, 0.5)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:32.806114Z","iopub.execute_input":"2023-01-16T22:26:32.806714Z","iopub.status.idle":"2023-01-16T22:26:32.821439Z","shell.execute_reply.started":"2023-01-16T22:26:32.806669Z","shell.execute_reply":"2023-01-16T22:26:32.819903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The code below did not work before as the dataset you were getting is stored in the kaggle input data. You were trying to install the data as a package so it did not work. I reccomned understanding the difference between the dataset and packages. A good place to start understanding stuff about kaggle is the Learn tab on the left hand side. The code I have added in a new cell uses the os package to use the directory and it basically loops through the dataset organized folder and any files/folders inside of it are added to a list. To not get the csv file as well I added an if statement that checks for whether it ends with a v or not. Hope this helps - Arav. ","metadata":{}},{"cell_type":"code","source":"#Code trying to get the image paths","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:32.823051Z","iopub.execute_input":"2023-01-16T22:26:32.824004Z","iopub.status.idle":"2023-01-16T22:26:32.837105Z","shell.execute_reply.started":"2023-01-16T22:26:32.823966Z","shell.execute_reply":"2023-01-16T22:26:32.836055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#def siim-isic-2019-organized as /kaggle/input/siim-isic-2019-organized as\n#pip install sim-isic-2019-organized","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:32.839839Z","iopub.execute_input":"2023-01-16T22:26:32.840637Z","iopub.status.idle":"2023-01-16T22:26:32.851047Z","shell.execute_reply.started":"2023-01-16T22:26:32.840590Z","shell.execute_reply":"2023-01-16T22:26:32.849730Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#from siim-isic-2019-organized import paths\n#import cv2","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:32.852791Z","iopub.execute_input":"2023-01-16T22:26:32.853220Z","iopub.status.idle":"2023-01-16T22:26:32.863793Z","shell.execute_reply.started":"2023-01-16T22:26:32.853156Z","shell.execute_reply":"2023-01-16T22:26:32.862475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#ImagePaths = list(paths.list_images(ssim-isic-2019-organized))","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:32.865299Z","iopub.execute_input":"2023-01-16T22:26:32.865635Z","iopub.status.idle":"2023-01-16T22:26:32.876839Z","shell.execute_reply.started":"2023-01-16T22:26:32.865605Z","shell.execute_reply":"2023-01-16T22:26:32.875670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\n# gets the directory of the dataset\ndirectory = \"/kaggle/input/siim-isic-2019-organized/dataset organized/\"\n# empty list to store the paths to the benign and malignant images\nimagePaths = []\nfor dirs in os.listdir(directory): \n    if dirs[-1] != \"v\":\n        dirs = directory+dirs\n        imagePaths.append(dirs)\nprint(imagePaths)","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:32.877871Z","iopub.execute_input":"2023-01-16T22:26:32.878255Z","iopub.status.idle":"2023-01-16T22:26:32.895089Z","shell.execute_reply.started":"2023-01-16T22:26:32.878221Z","shell.execute_reply":"2023-01-16T22:26:32.894105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os, warnings\nimport matplotlib.pyplot as plt\nfrom matplotlib import gridspec\nimport pandas as pd\nimport numpy as np\nimport tensorflow as tf\n#from tensorflow.keras.preprocessing import siim-isic-2019-organized","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:32.896447Z","iopub.execute_input":"2023-01-16T22:26:32.896967Z","iopub.status.idle":"2023-01-16T22:26:32.903508Z","shell.execute_reply.started":"2023-01-16T22:26:32.896934Z","shell.execute_reply":"2023-01-16T22:26:32.902506Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#x_train must be an array of all the malignant images\n\nfolder = \"/kaggle/input/siim-isic-2019-organized/dataset organized/malignant\"\n\nonlyfiles = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f))]\n\nprint(\"Working with {0} images\".format(len(onlyfiles)))\nprint(\"Image examples: \")\n\nfor i in range(40, 42):\n    print(onlyfiles[i])\n    #display(_Imgdis(filename=folder + \"/\" + onlyfiles[i], width=64, height=64))","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:32.904822Z","iopub.execute_input":"2023-01-16T22:26:32.905384Z","iopub.status.idle":"2023-01-16T22:26:33.234069Z","shell.execute_reply.started":"2023-01-16T22:26:32.905350Z","shell.execute_reply":"2023-01-16T22:26:33.232778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import PIL \nfrom PIL import Image","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:33.235864Z","iopub.execute_input":"2023-01-16T22:26:33.236702Z","iopub.status.idle":"2023-01-16T22:26:33.241254Z","shell.execute_reply.started":"2023-01-16T22:26:33.236648Z","shell.execute_reply":"2023-01-16T22:26:33.240321Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:33.243227Z","iopub.execute_input":"2023-01-16T22:26:33.243759Z","iopub.status.idle":"2023-01-16T22:26:33.254712Z","shell.execute_reply.started":"2023-01-16T22:26:33.243713Z","shell.execute_reply":"2023-01-16T22:26:33.253302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"channels = 3\nnb_classes = 1\n\nx_train = np.ndarray(shape=(len(onlyfiles), 222, 222, 1))\n\ni = 0\ncounter = 0\n\nfor _file in onlyfiles:\n    if(counter <= 34000):\n        img = Image.open(folder + \"/\" + _file)\n        img = img.resize(size=(222,222),resample=PIL.Image.NEAREST)\n        img = img.convert(\"1\")\n        #img = load_img(folder + \"/\" + _file, color_mode=\"grayscale\")  # this is a PIL image\n        # Convert to Numpy Array\n        x = img_to_array(img, data_format = \"channels_last\")  \n        #x = x.reshape((64, 64))\n        # Normalize\n        # x = (x - 128.0) / 128.0\n        x_train[i] = x\n        i += 1\n        counter += 1\n        if i % 1000 == 0:\n            print(\"%d images to array\" % i)\nprint(\"All images to array!\")","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:33.257129Z","iopub.execute_input":"2023-01-16T22:26:33.257516Z","iopub.status.idle":"2023-01-16T22:26:39.369849Z","shell.execute_reply.started":"2023-01-16T22:26:33.257484Z","shell.execute_reply":"2023-01-16T22:26:39.368593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Starting to create FCGAN (fully connected GAN)\n\n#creating generator portion of the GAN\n\n\n\nfrom keras.models import Sequential\nfrom keras.layers import Dense\nfrom keras.layers.advanced_activations import LeakyReLU\n\ndef create_generator():\n    generator = Sequential()\n\n    generator.add(Dense(256, input_dim=noise_dim))\n    generator.add(LeakyReLU(0.2))\n    \n    generator.add(Dense(512))\n    generator.add(LeakyReLU(0.2))\n    \n    generator.add(Dense(1024))\n    generator.add(LeakyReLU(0.2))\n    \n    generator.add(Dense(img_rows*img_cols*channels, activation='tanh'))  #The output layer has the same number of neurons as pixels in the image, because each neuron produces the color value for each pixel\n    \n    generator.compile(loss='binary_crossentropy', optimizer=optimizer) # A standard cross entropy loss would work, because the feedback it is getting is whether it fooled the discriminator or not.\n    \n    return generator\n    ","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:39.375086Z","iopub.execute_input":"2023-01-16T22:26:39.375694Z","iopub.status.idle":"2023-01-16T22:26:39.385447Z","shell.execute_reply.started":"2023-01-16T22:26:39.375646Z","shell.execute_reply":"2023-01-16T22:26:39.384190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#creating the discriminator for the GAN\n\ndef create_discriminator():\n    discriminator = Sequential()\n    \n    discriminator.add(Dense(1024, input_dim=222*222*1))\n    discriminator.add(LeakyReLU(0.2))\n    \n    discriminator.add(Dense(512))\n    discriminator.add(LeakyReLU(0.2))\n    \n    discriminator.add(Dense(256))\n    discriminator.add(LeakyReLU(0.2))\n    \n    discriminator.add(Dense(1, activation='sigmoid'))  #sigmoid activation as output is 0/1 fake/real\n    \n    discriminator.compile(loss='binary_crossentropy', optimizer = optimizer)  #Binary Cross entropy loss as the discriminator has to try and classify all images (real or fake) in the right category\n    \n    return discriminator","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:39.387028Z","iopub.execute_input":"2023-01-16T22:26:39.387627Z","iopub.status.idle":"2023-01-16T22:26:39.402631Z","shell.execute_reply.started":"2023-01-16T22:26:39.387581Z","shell.execute_reply":"2023-01-16T22:26:39.401719Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#combining the generator and discriminator to make a single large gan (loss and derivatives have to flow from discriminator to generator)\n\nfrom keras.layers import Input\nfrom keras.models import Model\n\ndiscriminator = create_discriminator()   #Creating the discriminator using the function\ngenerator = create_generator()           #Creating the generator using the function\n\ndiscriminator.trainable = False          #We will set this to false, so that when we train the entire GAN together, only the generator part will be trained. We will train the discriminator separately. See below code block for more details.\n\ngan_input = Input(shape=(noise_dim,1))    #We set the input of the whole model as the noise vector that the generator takes in as input. This is because the generator first has to develop an image for training to start.\nfake_image = generator(gan_input)        #Image generated by GAN for this noise vector is stored in fake_image\n\ngan_output = discriminator(fake_image)   #The output of the GAN is the discriminator\n\ngan = Model(gan_input, gan_output)       #Finally putting the generator and discriminator together\ngan.compile(loss='binary_crossentropy', optimizer=optimizer)  # Using binary cross entropy loss (same as discriminator loss)\n","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:31:08.102748Z","iopub.execute_input":"2023-01-16T22:31:08.103351Z","iopub.status.idle":"2023-01-16T22:31:09.149656Z","shell.execute_reply.started":"2023-01-16T22:31:08.103303Z","shell.execute_reply":"2023-01-16T22:31:09.147542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shape=(noise_dim,1)\nprint(shape)","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:32:33.304882Z","iopub.execute_input":"2023-01-16T22:32:33.305416Z","iopub.status.idle":"2023-01-16T22:32:33.312812Z","shell.execute_reply.started":"2023-01-16T22:32:33.305374Z","shell.execute_reply":"2023-01-16T22:32:33.311317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Code for plotting results\nimport matplotlib.pyplot as plt\n\ndef show_images(noise, size_fig):\n    generated_images = generator.predict(noise)   #Create the images from the GAN.\n    plt.figure(figsize=size_fig)\n    \n    for i, image in enumerate(generated_images):\n        plt.subplot(size_fig[0], size_fig[1], i+1)\n        if channels == 1:\n            plt.imshow(image.reshape((img_rows, img_cols)), cmap='gray')    #If the image is grayscale, as in our case, then we will reshape the output in the following way.\n                                                                            #Also, we set the coloring to grayscale so that it doesn't look like it came out of an infrared camera :)\n        else:\n            plt.imshow(image.reshape((img_rows, img_cols, channels)))\n        plt.axis('off')\n    \n    plt.tight_layout()   #Tight layout so that all of the generated images form a nice grid\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:40.758985Z","iopub.status.idle":"2023-01-16T22:26:40.759432Z","shell.execute_reply.started":"2023-01-16T22:26:40.759226Z","shell.execute_reply":"2023-01-16T22:26:40.759252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for epoch in range(epochs):         #iterate the dataset for the number of epochs\n    for batch in range(steps_per_epoch):    #for the number of batches we wanted to create\n        #noise = np.random.normal(0, 1, size=(batch_size, noise_dim))   #We generate a new noise vector to feed the generator before every training iteration\n        #fake_x = generator.predict(noise) #The image the generator develops for the noise vector we created above\n        #fake_X = np.expand_dims(fake_x, (2, 1))\n        \n        real_x = x_train  #We won't use all real images from our dataset at once, we will only select a random sample of images\n        #x = np.concatenate((real_x, fake_X))    #making the x dataset for the discriminator. This includes a mix of real and fake examples for the discriminator to correctly classify\n\n        disc_y = []\n        i = 0\n        while i < 49284:\n            disc_y.append(0.9)\n            i+=1\n\n        d_loss = discriminator.train_on_batch(real_x, disc_y)   #We are training the discriminator separately. Remember, we set trainable = false when adding it to the GAN, so that when we train the GAN, we only train the generator. Hence this extra step\n\n        y_gen = np.ones(batch_size)\n        g_loss = gan.train_on_batch(noise, y_gen)       #Now we train the entire GAN. But since the discriminator can't be trained, only the generator is trained in this step.\n\n    print(f'Epoch: {epoch + 1} \\t Discriminator Loss: {d_loss} \\t\\t Generator Loss: {g_loss}')\n    noise = np.random.normal(0, 1, size=(25, noise_dim))\n    show_images(noise, (5, 5))","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:40.761081Z","iopub.status.idle":"2023-01-16T22:26:40.761709Z","shell.execute_reply.started":"2023-01-16T22:26:40.761411Z","shell.execute_reply":"2023-01-16T22:26:40.761443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"noise = np.random.normal(0, 1, size=(100, noise_dim))\nshow_images(noise)","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:40.764026Z","iopub.status.idle":"2023-01-16T22:26:40.764677Z","shell.execute_reply.started":"2023-01-16T22:26:40.764362Z","shell.execute_reply":"2023-01-16T22:26:40.764391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Choose from one of the below datasets\nfrom keras.datasets import fashion_mnist\n#from keras.datasets import mnist\n\nimport os\n\n(x_train, y_train), (x_tet, y_test) = fashion_mnist.load_data()   #Load the data\n\nx_train = (x_train.astype(np.float32) - 127.5) / 127.5       #Normalize the images again so that the pixel value is from -1 to 1\n\nx_train = x_train.reshape(-1, img_rows, img_cols, channels)  #Reshaping the data into a more NN friendly format","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:40.766429Z","iopub.status.idle":"2023-01-16T22:26:40.767259Z","shell.execute_reply.started":"2023-01-16T22:26:40.766895Z","shell.execute_reply":"2023-01-16T22:26:40.766924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.initializers import RandomNormal\nfrom keras.layers import Dense, Conv2D, Conv2DTranspose, Reshape\nfrom keras.layers.advanced_activations import LeakyReLU\nfrom keras.models import Sequential\n\n\ndef create_generator_cgan():\n    generator = Sequential()\n    \n    d = 7\n    generator.add(Dense(d*d*256, kernel_initializer=RandomNormal(0, 0.02), input_dim=noise_dim))\n    generator.add(LeakyReLU(0.2))     #We are going to use the same leaky relu activation function as the FCGAN.\n    \n    generator.add(Reshape((d, d, 256)))\n    \n    generator.add(Conv2DTranspose(128, (4, 4), strides=2, padding='same', kernel_initializer=RandomNormal(0, 0.02)))\n    generator.add(LeakyReLU(0.2))\n\n    generator.add(Conv2DTranspose(128, (4, 4), strides=2, padding='same', kernel_initializer=RandomNormal(0, 0.02)))\n    generator.add(LeakyReLU(0.2))\n    \n\n    \n    generator.add(Conv2D(channels, (3, 3), padding='same', activation='tanh', kernel_initializer=RandomNormal(0, 0.02)))  #Remember that the final activation has to be tanh, since pixel values go from -1 to 1\n    \n    generator.compile(loss='binary_crossentropy', optimizer=optimizer)    #The loss doesn't change when you use convolutional layers\n    return generator","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:40.769103Z","iopub.status.idle":"2023-01-16T22:26:40.769930Z","shell.execute_reply.started":"2023-01-16T22:26:40.769623Z","shell.execute_reply":"2023-01-16T22:26:40.769652Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.initializers import RandomNormal\nfrom keras.layers import Dense, Conv2D, Flatten, Reshape, Dropout\nfrom keras.layers.advanced_activations import LeakyReLU\nfrom keras.models import Sequential\n\ndef create_discriminator_cgan():\n    discriminator = Sequential()\n    \n    discriminator.add(Conv2D(64, (3, 3), padding='same', kernel_initializer=RandomNormal(0, 0.02), input_shape=(img_cols, img_rows, channels)))\n    discriminator.add(LeakyReLU(0.2))\n    \n    discriminator.add(Conv2D(128, (3, 3), strides=2, padding='same', kernel_initializer=RandomNormal(0, 0.02)))\n    discriminator.add(LeakyReLU(0.2))\n    \n    discriminator.add(Conv2D(128, (3, 3), strides=2, padding='same', kernel_initializer=RandomNormal(0, 0.02)))\n    discriminator.add(LeakyReLU(0.2))\n    \n    discriminator.add(Conv2D(256, (3, 3), strides=2, padding='same', kernel_initializer=RandomNormal(0, 0.02)))\n    discriminator.add(LeakyReLU(0.2))\n    \n    discriminator.add(Flatten())\n    discriminator.add(Dropout(0.4))\n    discriminator.add(Dense(1, activation='sigmoid', input_shape=(img_cols, img_rows, channels)))\n    \n    discriminator.compile(loss='binary_crossentropy', optimizer=optimizer)  #Again, the loss doesn't change when creating a DCGAN.\n    return discriminator","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:40.771857Z","iopub.status.idle":"2023-01-16T22:26:40.772449Z","shell.execute_reply.started":"2023-01-16T22:26:40.772140Z","shell.execute_reply":"2023-01-16T22:26:40.772186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.layers import Input\nfrom keras.models import Model\n\ndiscriminator = create_discriminator_cgan()\ngenerator = create_generator_cgan()\n\ndiscriminator.trainable = False\n\ngan_input = Input(shape=(noise_dim,))\nfake_image = generator(gan_input)\n\ngan_output = discriminator(fake_image)\n\ngan = Model(gan_input, gan_output)\ngan.compile(loss='binary_crossentropy', optimizer=optimizer)","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:40.774619Z","iopub.status.idle":"2023-01-16T22:26:40.775274Z","shell.execute_reply.started":"2023-01-16T22:26:40.774924Z","shell.execute_reply":"2023-01-16T22:26:40.774952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train = x_train[np.where(y_train == 0)[0]]","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:40.778180Z","iopub.status.idle":"2023-01-16T22:26:40.778827Z","shell.execute_reply.started":"2023-01-16T22:26:40.778507Z","shell.execute_reply":"2023-01-16T22:26:40.778536Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image = x_train[29]\nplt.imshow(image.reshape((img_rows, img_cols)), cmap='gray')","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:40.780510Z","iopub.status.idle":"2023-01-16T22:26:40.781122Z","shell.execute_reply.started":"2023-01-16T22:26:40.780822Z","shell.execute_reply":"2023-01-16T22:26:40.780859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Whatisrandom.randint\nfor epoch in range(epochs):\n    for batch in range(steps_per_epoch):\n        noise = np.random.normal(0, 1, size=(batch_size, noise_dim))\n        fake_x = generator.predict(noise)\n\n        real_x = x_train[np.random.randint(0, x_train.shape[0], size=batch_size)]\n        #print(real_x.shape)\n        #print(fake_x.shape)\n        x = np.concatenate((real_x, fake_x))\n\n        disc_y = np.zeros(2*batch_size)\n        disc_y[:batch_size] = 0.9\n\n        d_loss = discriminator.train_on_batch(x, disc_y)\n\n        y_gen = np.ones(batch_size)\n        g_loss = gan.train_on_batch(noise, y_gen)\n\n    print(f'Epoch: {epoch + 1} \\t Discriminator Loss: {d_loss} \\t\\t Generator Loss: {g_loss}')\n    noise = np.random.normal(0, 1, size=(25, noise_dim))\n    show_images(noise, (5, 5))","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:40.783313Z","iopub.status.idle":"2023-01-16T22:26:40.783956Z","shell.execute_reply.started":"2023-01-16T22:26:40.783625Z","shell.execute_reply":"2023-01-16T22:26:40.783657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"noise = np.random.normal(0, 1, size=(100, noise_dim))\nshow_images(noise, (10, 10))","metadata":{"execution":{"iopub.status.busy":"2023-01-16T22:26:40.785838Z","iopub.status.idle":"2023-01-16T22:26:40.786435Z","shell.execute_reply.started":"2023-01-16T22:26:40.786124Z","shell.execute_reply":"2023-01-16T22:26:40.786152Z"},"trusted":true},"execution_count":null,"outputs":[]}]}