Kaggle competition: Generative Dog Images
df_all['len_of_query'] = df_all['search_term'].map(lambda x:len(x.split())).astype(np.int64)
 df_all['len_of_title'] = df_all['product_title'].map(lambda x:len(x.split())).astype(np.int64)
 df_all['len_of_description'] = df_all['product_description'].map(lambda x:len(x.split())).astype(np.int64)
 df_all['len_of_brand'] = df_all['brand'].map(lambda x:len(x.split())).astype(np.int64)
 df_all['product_info'] = df_all['search_term']+"\t"+df_all['product_title'] +"\t"+df_all['product_description']
df_all['query_in_title'] = df_all['product_info'].map(lambda x:str_whole_word(x.split('\t')[0],x.split('\t')[1],0))
df_all['query_in_description'] = df_all['product_info'].map(lambda x:str_whole_word(x.split('\t')[0],x.split('\t')[2],0))
df_all['word_in_title'] = df_all['product_info'].map(lambda x:str_common_word(x.split('\t')[0],x.split('\t')[1]))
df_all['word_in_description'] = df_all['product_info'].map(lambda x:str_common_word(x.split('\t')[0],x.split('\t')[2]))
df_all['ratio_title'] = df_all['word_in_title']/df_all['len_of_query']
df_all['ratio_description'] = df_all['word_in_description']/df_all['len_of_query']
df_all['attr'] = df_all['search_term']+"\t"+df_all['brand']+"\t"+df_all['product_title']
df_all['word_in_brand'] = df_all['attr'].map(lambda x:str_common_word(x.split('\t')[0],x.split('\t')[1]))
df_all['ratio_brand'] = df_all['word_in_brand']/df_all['len_of_brand']
df_all = df_all.drop(['search_term','product_title','product_description','product_info','attr','brand'],axis=1)
 df_all.head()
print(df_all[:10])
<prepare_x_and_y>
ComputeLB = False
DogsOnly = True
ROOT = '.. /input/'
IMAGES = os.listdir(ROOT + 'all-dogs/all-dogs/')
 breeds = os.listdir(ROOT + 'annotation/Annotation/')
 idxIn = 0; namesIn = []
imagesIn = np.zeros(( 25000,64,64,3))
imagesIn2 = np.zeros(( 25000,64,64))
if DogsOnly:
for breed in breeds:
for dog in os.listdir(ROOT+'annotation/Annotation/'+breed):
try: img = Image.open(ROOT+'all-dogs/all-dogs/'+dog+'.jpg')
 except: continue
tree = ET.parse(ROOT+'annotation/Annotation/'+breed+'/'+dog)
 root = tree.getroot()
objects = root.findall('object')
 for o in objects:
bndbox = o.find('bndbox')
 xmin = int(bndbox.find('xmin' ).text)
 ymin = int(bndbox.find('ymin' ).text)
 xmax = int(bndbox.find('xmax' ).text)
 ymax = int(bndbox.find('ymax' ).text)
 w = np.min(( xmax - xmin, ymax - ymin))
img2 = img.crop(( xmin, ymin, xmin+w, ymin+w))
img3 = img2
img3 = img3.transpose(Image.FLIP_LEFT_RIGHT)
 img3 = img3.resize(( 64,64), Image.ANTIALIAS)
 img3 = img3.convert('LA')
 img2 = img2.resize(( 64,64), Image.ANTIALIAS)
 imagesIn[idxIn,:,:,:] = np.asarray(img2)
 imagesIn2[idxIn,:,:] = np.asarray(img3)[:,:,0]
namesIn.append(breed)
 idxIn += 1
idx = np.arange(idxIn)
 np.random.shuffle(idx)
 imagesIn = imagesIn[idx,:,:,:]
imagesIn2 = imagesIn2[idx,:,:]
namesIn = np.array(namesIn)[idx]
else:
IMAGES = np.sort(IMAGES)
 np.random.seed(810)
 x = np.random.choice(np.arange(20579),10000)
 np.random.seed(None)
 for k in range(len(x)) :
img = Image.open(ROOT + 'all-dogs/all-dogs/' + IMAGES[x[k]])
 w = img.size[0]; h = img.size[1];
if(k%2==0)|(k%3==0):
w2 = 100; h2 = int(h/(w/100))
a = 18; b = 0
else:
a=0; b=0
if w<h:
w2 = 64; h2 = int(( 64/w)*h)
 b =(h2-64)//2
else:
h2 = 64; w2 = int(( 64/h)*w)
 a =(w2-64)//2
img = img.resize(( w2,h2), Image.ANTIALIAS)
 img = img.crop(( 0+a, 0+b, 64+a, 64+b))
imagesIn[idxIn,:,:,:] = np.asarray(img)
 namesIn.append(IMAGES[x[k]])
 idxIn += 1
df_train = df_all.iloc[:num_train]
df_test = df_all.iloc[num_train:]
id_test = df_test['id']
y_train = df_train['relevance'].values
X_train = df_train.drop(['id','relevance'],axis=1 ).values
X_test = df_test.drop(['id','relevance'],axis=1 ).values<train_on_grid>
plt.imshow(Image.fromarray(( imagesIn[101] ).astype('uint8' ).reshape(( 64,64,3))))
RMSE = make_scorer(fmean_squared_error, greater_is_better=False)
 rfr = RandomForestRegressor()
clf = pipeline.Pipeline([('rfr', rfr)])
 param_grid = {'rfr__n_estimators' : list(range(109,111,1)) ,
'rfr__max_depth': list(range(7,9,1))
}
model = grid_search.GridSearchCV(estimator = clf, param_grid = param_grid, n_jobs = -1, cv = 10, verbose = 150, scoring=RMSE)
 model.fit(X_train, y_train)
 print("Best parameters found by grid search:")
 print(model.best_params_)
 print("Best CV score:")
 print(model.best_score_)
 y_pred = model.predict(X_test)
 print(len(y_pred))
pd.DataFrame({"id": id_test, "relevance": y_pred} ).to_csv('submission2.csv',index=False )<set_options>
from keras.models import Model
from keras.layers import Input, Dense, Conv2D, Reshape, Flatten, concatenate
from keras.preprocessing.image import ImageDataGenerator
from keras.callbacks import LearningRateScheduler
from keras.optimizers import SGD, Adam
%matplotlib inline
warnings.filterwarnings("ignore" )<load_from_csv>
def define_discriminator(in_shape=(28,28,1)) :
model = Sequential()
model.add(Conv2D(128,(3,3), strides=(2,2), padding='same', input_shape=in_shape))
model.add(LeakyReLU(alpha=0.2))
model.add(Conv2D(128,(3,3), strides=(2,2), padding='same'))
model.add(LeakyReLU(alpha=0.2))
model.add(Flatten())
 model.add(Dropout(0.4))
model.add(Dense(1, activation='sigmoid'))
opt = Adam(lr=0.0002, beta_1=0.5)
 model.compile(loss='binary_crossentropy', optimizer=opt, metrics=['accuracy'])
 return model
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv' )<load_from_csv>
def define_discriminator(in_shape=(28,28,1), n_classes=10):
	
	in_label = Input(shape=(1,))
	
	li = Embedding(n_classes, 50 )(in_label)
 	
	n_nodes = in_shape[0] * in_shape[1]
	li = Dense(n_nodes )(li)
 	
	li = Reshape(( in_shape[0], in_shape[1], 1))(li)
 	
	in_image = Input(shape=in_shape)
 	
	merge = Concatenate()([in_image, li])
 	
	fe = Conv2D(128,(3,3), strides=(2,2), padding='same' )(merge)
 	fe = LeakyReLU(alpha=0.2 )(fe)
 	
	fe = Conv2D(128,(3,3), strides=(2,2), padding='same' )(fe)
 	fe = LeakyReLU(alpha=0.2 )(fe)
 	
	fe = Flatten()(fe)
 	
	fe = Dropout(0.4 )(fe)
 	
	out_layer = Dense(1, activation='sigmoid' )(fe)
 	
	model = Model([in_image, in_label], out_layer)
 	
	opt = Adam(lr=0.0002, beta_1=0.5)
 	model.compile(loss='binary_crossentropy', optimizer=opt, metrics=['accuracy'])
 	return model
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv' )<data_type_conversions>
NNimage = 4096
train.dependency = train.dependency.replace({"yes": 1, "no": 0} ).astype(np.float64)
 train.edjefa = train.edjefa.replace({"yes": 1, "no": 0} ).astype(np.float64)
 train.edjefe = train.edjefe.replace({"yes": 1, "no": 0} ).astype(np.float64)
 test.dependency = test.dependency.replace({"yes": 1, "no": 0} ).astype(np.float64)
 test.edjefa = test.edjefa.replace({"yes": 1, "no": 0} ).astype(np.float64)
 test.edjefe = test.edjefe.replace({"yes": 1, "no": 0} ).astype(np.float64 )<data_type_conversions>
dog = Input(( NNimage,))
dogName = Input(( 10000,))
x = Dense(NNimage, activation='sigmoid' )(dogName)
 x = Reshape(( 2,NNimage,1))(concatenate([dog,x]))
x = Conv2D(1,(2,1),use_bias=False,name='conv' )(x)
 discriminated = Flatten()(x)
 discriminator = Model([dog,dogName], discriminated)
 discriminator.get_layer('conv' ).trainable = False
discriminator.get_layer('conv' ).set_weights([np.array([[[[-1.0 ]]],[[[1.0]]]])])
 discriminator.compile(optimizer='adam', loss='binary_crossentropy')
train.rez_esc = train.rez_esc.replace({99.0 : 5.0} ).astype(np.float64)
 test.rez_esc = test.rez_esc.replace({99.0 : 5.0} ).astype(np.float64 )<define_variables>
train_y =(imagesIn2[:10000,:,:]/255.).reshape(( -1,NNimage))
train_X = np.zeros(( 10000,10000))
for i in range(10000): train_X[i,i] = 1
zeros = np.zeros(( 10000,NNimage))
lr = 0.5
for k in range(4):
annealer = LearningRateScheduler(lambda x: lr)
 h = discriminator.fit([zeros,train_X], train_y, epochs = 20, batch_size=256, callbacks=[annealer], verbose=0)
 print('Epoch',(k+1)*10,'/50 - loss =',h.history['loss'][-1])
 if h.history['loss'][-1]<0.530: lr = 0.1
ind_bool = ['v18q', 'dis', 'male', 'female', 'estadocivil1', 'estadocivil2', 'estadocivil3',
'estadocivil4', 'estadocivil5', 'estadocivil6', 'estadocivil7',
'parentesco1', 'parentesco2', 'parentesco3', 'parentesco4', 'parentesco5',
'parentesco6', 'parentesco7', 'parentesco8', 'parentesco9', 'parentesco10',
'parentesco11', 'parentesco12', 'instlevel1', 'instlevel2', 'instlevel3',
'instlevel4', 'instlevel5', 'instlevel6', 'instlevel7', 'instlevel8',
'instlevel9', 'mobilephone']
ind_non_bool = ['rez_esc', 'escolari', 'age','SQBescolari','SQBage','agesq']
hh_bool = ['hacdor', 'hacapo', 'v14a', 'refrig', 'paredblolad', 'paredzocalo',
'paredpreb','pisocemento', 'pareddes', 'paredmad',
'paredzinc', 'paredfibras', 'paredother', 'pisomoscer', 'pisoother',
'pisonatur', 'pisonotiene', 'pisomadera',
'techozinc', 'techoentrepiso', 'techocane', 'techootro', 'cielorazo',
'abastaguadentro', 'abastaguafuera', 'abastaguano',
'public', 'planpri', 'noelec', 'coopele', 'sanitario1',
'sanitario2', 'sanitario3', 'sanitario5', 'sanitario6',
'energcocinar1', 'energcocinar2', 'energcocinar3', 'energcocinar4',
'elimbasu1', 'elimbasu2', 'elimbasu3', 'elimbasu4',
'elimbasu5', 'elimbasu6', 'epared1', 'epared2', 'epared3',
'etecho1', 'etecho2', 'etecho3', 'eviv1', 'eviv2', 'eviv3',
'tipovivi1', 'tipovivi2', 'tipovivi3', 'tipovivi4', 'tipovivi5',
'computer', 'television', 'lugar1', 'lugar2', 'lugar3',
'lugar4', 'lugar5', 'lugar6', 'area1', 'area2']
hh_non_bool = ['v2a1', 'v18q1', 'meaneduc', 'SQBovercrowding', 'SQBdependency',
'SQBmeaned', 'overcrowding', 'rooms', 'r4h1', 'r4h2', 'r4h3', 'r4m1',
'r4m2', 'r4m3', 'r4t1', 'r4t2', 'r4t3', 'tamhog', 'tamviv', 'hhsize',
'hogar_nin', 'hogar_adul', 'hogar_mayor', 'hogar_total', 'bedrooms',
'qmobilephone', 'SQBhogar_total', 'SQBedjefe', 'SQBhogar_nin']
hh_cont = [ 'dependency', 'edjefe', 'edjefa']
ids = ['Id', 'idhogar', 'Target']<concatenate>
print('Epoch',(k+1)*10,'/50 - loss =',h.history['loss'][-1] )
test['Target'] = np.nan
data = train.append(test)
 data.info()<count_unique_values>
def define_generator(latent_dim):
	model = Sequential()
	
	n_nodes = 128 * 7 * 7
	model.add(Dense(n_nodes, input_dim=latent_dim))
	model.add(LeakyReLU(alpha=0.2))
	model.add(Reshape(( 7, 7, 128)))
 	
	model.add(Conv2DTranspose(128,(4,4), strides=(2,2), padding='same'))
	model.add(LeakyReLU(alpha=0.2))
	
	model.add(Conv2DTranspose(128,(4,4), strides=(2,2), padding='same'))
	model.add(LeakyReLU(alpha=0.2))
	
	model.add(Conv2D(1,(7,7), activation='tanh', padding='same'))
	return model
train.idhogar.nunique() , test.idhogar.nunique() , data.idhogar.nunique()<count_missing_values>
def define_generator(latent_dim, n_classes=120):
	
	in_label = Input(shape=(1,))
	
	li = Embedding(n_classes, 50 )(in_label)
 	
	n_nodes = 7 * 7
	li = Dense(n_nodes )(li)
 	
	li = Reshape(( 7, 7, 1))(li)
 	
	in_lat = Input(shape=(latent_dim,))
	
	n_nodes = 128 * 7 * 7
	gen = Dense(n_nodes )(in_lat)
 	gen = LeakyReLU(alpha=0.2 )(gen)
 	gen = Reshape(( 7, 7, 128))(gen)
 	
	merge = Concatenate()([gen, li])
 	
	gen = Conv2DTranspose(128,(4,4), strides=(2,2), padding='same' )(merge)
 	gen = LeakyReLU(alpha=0.2 )(gen)
 	
	gen = Conv2DTranspose(128,(4,4), strides=(2,2), padding='same' )(gen)
 	gen = LeakyReLU(alpha=0.2 )(gen)
 	
	out_layer = Conv2D(1,(7,7), activation='tanh', padding='same' )(gen)
 	
	model = Model([in_lat, in_label], out_layer)
 	return model
miss_count = data.isnull().sum() > 0
misvalue_counts = data.isnull().sum() [miss_count]
misvalue_percent = misvalue_counts/data.shape[0]*100
misvalue_percent<choose_model_class>
discriminator.trainable=False
gan_input = Input(shape=(10000,))
x = generator(gan_input)
 gan_output = discriminator(x)
 gan = Model(gan_input, gan_output)
 gan.get_layer('model_1' ).get_layer('conv' ).set_weights([np.array([[[[-1 ]]],[[[255.]]]])])
 gan.compile(optimizer=Adam(5), loss='mean_squared_error')
imputer = SimpleImputer(missing_values=np.nan, strategy='mean' )<prepare_x_and_y>
train = np.zeros(( 10000,10000))
for i in range(10000): train[i,i] = 1
zeros = np.zeros(( 10000,NNimage))
lr = 5.
 for k in range(20):
annealer = LearningRateScheduler(lambda x: lr)
 h = gan.fit(train, zeros, epochs = 1, batch_size=256, callbacks=[annealer], verbose=0)
 if(k<10)|(k%5==4):
print('Epoch',(k+1)*10,'/500 - loss =',h.history['loss'][-1])
 if h.history['loss'][-1] < 25: lr = 1.
 if h.history['loss'][-1] < 1.5: lr = 0.5
if k<10:
plt.figure(figsize=(15,3))
for j in range(5):
xx = np.zeros(( 10000))
xx[np.random.randint(10000)] = 1
plt.subplot(1,5,j+1)
 img = generator.predict(xx.reshape(( -1,10000)))[0]
img = Image.fromarray(( img ).astype('uint8' ).reshape(( 64,64)))
 plt.axis('off')
 plt.imshow(img, cmap='Greys')
 plt.show()
hh_train = train.loc[train.parentesco1 == 1, ids+hh_bool+hh_non_bool+hh_cont].reset_index()
target = hh_train[['Target']]
hh_train_ids = hh_train[['idhogar']]
hh_train = hh_train.drop(['Id','idhogar','Target','index'], axis=1)
 hh_train_df = pd.DataFrame(imputer.fit_transform(hh_train),columns=list(hh_train.columns))
hh_train['idhogar'] = hh_train_ids
hh_train_df['idhogar'] = hh_train_ids
hh_train['Target'] = target
hh_train_df['Target'] = target<prepare_x_and_y>
warnings.filterwarnings('ignore', category=UserWarning, module='skimage')
 seed = 42
random.seed = seed
np.random.seed = seed
ind_train = train.loc[ :, ids+ind_bool+ind_non_bool].reset_index()
ind_train_ids = ind_train[['idhogar']]
ind_target = ind_train[['Target']]
ind_train = ind_train.drop(['Id','idhogar','Target','index'], axis=1)
 ind_train_df=pd.DataFrame(imputer.fit_transform(ind_train),columns=list(ind_train.columns))
ind_train['idhogar'] = ind_train_ids
ind_train['Target'] = ind_target
ind_train_df['idhogar'] = ind_train_ids
ind_train_df['Target'] = ind_target<groupby>
IMG_WIDTH = 64
IMG_HEIGHT = 64
IMG_CHANNELS = 3
INPUT_SHAPE=(IMG_HEIGHT, IMG_WIDTH, 1)
mis_hh = test.groupby(by='idhogar' ).parentesco1.agg('sum')==0
mis_idhogar = test.groupby(by='idhogar' ).parentesco1.agg('sum')[mis_hh].index<sort_values>
L_enc = sklearn.preprocessing.LabelEncoder()
labels = L_enc.fit_transform(namesIn )
pd.options.display.max_columns = 10
test.loc[test.idhogar.isin(mis_idhogar),:][['Id','idhogar','parentesco1']].sort_values(by='idhogar' )<feature_engineering>
def Colorize() :
in_label = Input(shape=(1,))
embed_input = Embedding(120, 1000 )(in_label)
 encoder_input = Input(shape=(IMG_WIDTH, IMG_HEIGHT, 1,))
encoder_output = Conv2D(32,(3,3), activation='relu', padding='same',strides=1 )(encoder_input)
 encoder_output = MaxPooling2D(( 2, 2), padding='same' )(encoder_output)
 encoder_output = Conv2D(32,(4,4), activation='relu', padding='same' )(encoder_output)
 encoder_output = Conv2D(32,(3,3), activation='relu', padding='same',strides=1 )(encoder_output)
 encoder_output = MaxPooling2D(( 2, 2), padding='same' )(encoder_output)
 encoder_output = Conv2D(64,(4,4), activation='relu', padding='same' )(encoder_output)
 encoder_output = Conv2D(64,(3,3), activation='relu', padding='same',strides=1 )(encoder_output)
 encoder_output = MaxPooling2D(( 2, 2), padding='same' )(encoder_output)
 encoder_output = Conv2D(64,(4,4), activation='relu', padding='same' )(encoder_output)
 encoder_output = Conv2D(64,(3,3), activation='relu', padding='same' )(encoder_output)
 encoder_output = Conv2D(64,(3,3), activation='relu', padding='same' )(encoder_output)
 fusion_output = Dense(4096, activation='relu' )(embed_input)
 fusion_output = Reshape(( [8, 8, 64]))(fusion_output)
 fusion_output = concatenate([encoder_output, fusion_output], axis=3)
 fusion_output = Conv2D(64,(1, 1), activation='relu', padding='same' )(fusion_output)
 decoder_output = Conv2D(64,(3,3), activation='relu', padding='same' )(fusion_output)
 decoder_output = Conv2D(32,(3,3), activation='relu', padding='same' )(decoder_output)
 decoder_output = UpSampling2D(( 2, 2))(decoder_output)
 decoder_output = Conv2D(64,(3,3), activation='relu', padding='same' )(decoder_output)
 decoder_output = UpSampling2D(( 2, 2))(decoder_output)
 decoder_output = Conv2D(128,(4,4), activation='relu', padding='same' )(decoder_output)
 decoder_output = Conv2D(128,(3,3), activation='relu', padding='same' )(decoder_output)
 decoder_output = Conv2D(32,(2,2), activation='relu', padding='same' )(decoder_output)
 decoder_output = Conv2D(3,(3, 3), activation='tanh', padding='same' )(decoder_output)
 decoder_output = UpSampling2D(( 2, 2))(decoder_output)
 return Model(inputs=[encoder_input, in_label], outputs=decoder_output)
 model = Colorize()
model.compile(optimizer='adam', loss='mean_squared_error')
 model.summary()
test.loc[test.Id == 'ID_99d27ab2f','parentesco1'] = 1
test.loc[test.Id == 'ID_49d05f9e6','parentesco1'] = 1
test.loc[test.Id == 'ID_b0874f522','parentesco1'] = 1
test.loc[test.Id == 'ID_ceeb5dfe2','parentesco1'] = 1
test.loc[test.Id == 'ID_aa8f26c06','parentesco1'] = 1
test.loc[test.Id == 'ID_e42c1dde2','parentesco1'] = 1
test.loc[test.Id == 'ID_9c12f6ebc','parentesco1'] = 1
test.loc[test.Id == 'ID_26d95edff','parentesco1'] = 1
test.loc[test.Id == 'ID_93fa2f7cc','parentesco1'] = 1
test.loc[test.Id == 'ID_bca8a1dde','parentesco1'] = 1
test.loc[test.Id == 'ID_4036d87e3','parentesco1'] = 1
test.loc[test.Id == 'ID_9f025fde6','parentesco1'] = 1
test.loc[test.Id == 'ID_6094ce990','parentesco1'] = 1
test.loc[test.Id == 'ID_00e8a868f','parentesco1'] = 1
test.loc[test.Id == 'ID_d0beee31f','parentesco1'] = 1
test.loc[test.Id == 'ID_894de66bc','parentesco1'] = 1
test.loc[test.Id == 'ID_aa650fb4a','parentesco1'] = 1
test.loc[test.Id == 'ID_139a474f3','parentesco1'] = 1<prepare_x_and_y>
X_train = imagesIn / 256 .
hh_test = test.loc[test.parentesco1 == 1, ids+hh_bool+hh_non_bool+hh_cont].reset_index()
hh_test_ids = hh_test[['idhogar']]
hh_test = hh_test.drop(['Id','idhogar','Target','index'], axis = 1)
 hh_test_df = pd.DataFrame(imputer.fit_transform(hh_test),columns=list(hh_test.columns))
hh_test_df['idhogar'] = hh_test_ids
hh_test['idhogar'] = hh_test_ids<drop_column>
datagen = ImageDataGenerator(
 shear_range=0.2,
zoom_range=0.2,
rotation_range=20,
horizontal_flip=True)
 def image_a_b_gen(dataset=X_train, batch_size = 20):
for batch in datagen.flow(dataset, batch_size=batch_size):
X_batch = rgb2gray(batch)
 lab_batch = rgb2lab(batch)
 X_batch = lab_batch[:,:,:,0]
X_batch = X_batch.reshape(X_batch.shape+(1,))
Y_batch = lab_batch[:,:,:,1:] / 128
yield [X_batch, label_batch], Y_batch
learning_rate_reduction = ReduceLROnPlateau(monitor='loss',
patience=3,
verbose=1,
factor=0.5,
min_lr=0.00001)
 filepath = "Art_Colorization_Model.h5"
checkpoint = ModelCheckpoint(filepath,
save_best_only=True,
monitor='loss',
mode='min')
 model_callbacks = [learning_rate_reduction,checkpoint]
ind_test = test.loc[:, ids+ind_bool+ind_non_bool].reset_index()
ind_test_ids = ind_test[['idhogar']]
ind_test = ind_test.drop(['Id','idhogar','Target','index'], axis = 1)
 ind_test_df = pd.DataFrame(imputer.fit_transform(ind_test),columns=list(ind_test.columns))
ind_test['idhogar'] = ind_test_ids
ind_test_df['idhogar'] = ind_test_ids<create_dataframe>
model.fit([X_batch,labels],X_train,
epochs=6,
verbose=1 )
<merge><EOS> 
class DogGenerator:
index = 0
def getDog(self,seed):
xx = np.zeros(( 10000))
xx = np.zeros(( 10000))
xx[np.random.randint(10000)] = 1
img = generator.predict(xx.reshape(( -1,10000)))[0].reshape(( 64,64))
self.index =(self.index+1)%10000
return Image.fromarray(( img ).astype('uint8' ).reshape(( 64,64)))