<jupyter_start><jupyter_text>Imports<jupyter_code>import pandas as pd
import numpy as np
import os

import tensorflow as tf

from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.preprocessing.image import ImageDataGenerator

import tensorflow_addons as tfa

import pandas as pd
import urllib.request
from urllib.parse import urlparse

import warnings
warnings.simplefilter(action='ignore')<jupyter_output><empty_output><jupyter_text>Load Data<jupyter_code>df_train = pd.read_parquet('../input/movie-posters-2/df_train-split_v1.gzip')
df_val = pd.read_parquet('../input/movie-posters-2/df_eval-split_v1.gzip')
df_test = pd.read_parquet('../input/movie-posters-2/df_test-split_v1.gzip')

def get_path_from_url(url):
    if url is None:
        return None    
    return url.split('/')[-1]

df_train['filename'] = df_train['poster_url'].apply(get_path_from_url)
df_val['filename'] = df_val['poster_url'].apply(get_path_from_url)
df_test['filename'] = df_test['poster_url'].apply(get_path_from_url)

display(df_train.head(2))
display(df_val.head(2))
display(df_test.head(2))
df_train.shape, df_val.shape, df_test.shape<jupyter_output><empty_output><jupyter_text>Create Image generators for train, validate and test<jupyter_code>IMAGES_DIR = '../input/movie-posters-2/data'

label_cols = [col for col in df_train.columns if col.startswith('x0_')]
datagen = ImageDataGenerator()

train_generator = datagen.flow_from_dataframe(
    dataframe=df_train,
    directory=IMAGES_DIR,
    x_col="filename",
    y_col=label_cols,
    batch_size=64,
    shuffle=True,
    class_mode="raw",    
    target_size=(299, 299),
)

valid_generator = datagen.flow_from_dataframe(
    dataframe=df_val,
    directory=IMAGES_DIR,
    x_col="filename",
    y_col=label_cols,
    batch_size=64,
    class_mode="raw",
    target_size=(299, 299)
)

test_generator = datagen.flow_from_dataframe(
    dataframe=df_test,
    directory=IMAGES_DIR,
    x_col="filename",
    y_col=label_cols,
    batch_size=64,
    class_mode="raw",
    target_size=(299, 299),
    validate_filenames=True
)<jupyter_output><empty_output><jupyter_text>Create Random Model<jupyter_code>m1 = keras.Sequential()
m1.add(
    layers.Lambda(lambda x: tf.random.uniform((1,19), minval=0.0, maxval=1.0), input_shape=(299,299,3))
    )
m1.compile(optimizer='adam', loss='binary_crossentropy', 
           metrics=['accuracy',
                    tfa.metrics.FBetaScore(num_classes=19, average='micro', threshold=0.5, name='f1_score_micro',),
                    tfa.metrics.FBetaScore(num_classes=19, average='weighted', threshold=0.5, name='f1_score_weighted'),])
m1.evaluate(test_generator)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1279673590504451, 'fraction_numerical': 0.02373887240356083, 'mean_word_length': 5.360849056603773, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '48011', 'license': 'FTL', 'n_tokens_mistral': 1028, 'n_tokens_neox': 984, 'n_words': 144, 'path': 'notebooks/andras/movie-random-02.ipynb', 'repo_name': 'rainerenglisch/AIDA_movie_genre', 'size': '2696'}