CHESS CONFIGURATION
FEN Generator for Chess Configuration Chalenge
A solution code for Chess Configuration Chalenge
This trained model may be used for solution others puzzles of the chelenge.😉
Chess FEN Generator¶
Original: \ https://www.kaggle.com/koryakinp/chess-fen-generator
Download Data¶
In [1]:
!pip install --upgrade fastai git+https://gitlab.aicrowd.com/yoogottamk/aicrowd-cli.git >/dev/null
%load_ext aicrowd.magic
In [2]:
API_KEY = '' #Please enter your API Key [https://www.aicrowd.com/participants/me]
%aicrowd login --api-key $API_KEY
In [3]:
%aicrowd dataset download --challenge chess-configuration -j 3
In [4]:
!rm -rf data
!mkdir data
!unzip -q train.zip -d data/
!unzip -q val.zip -d data/
!unzip -q test.zip -d data/
!mv train.csv data/train.csv
!mv val.csv data/val.csv
!mv sample_submission.csv data/sample_submission.csv
Import packages¶
In [5]:
import numpy as np
import pandas as pd
import os
import glob
import re
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from random import shuffle
from skimage.util.shape import view_as_blocks
from skimage import io, transform
from sklearn.model_selection import train_test_split
from keras.models import Sequential, load_model
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.convolutional import Convolution2D
import warnings
warnings.filterwarnings('ignore')
Data Import¶
In [6]:
#DATADIR = 'D:/Datasets/CHESS/CONFIGURATION/'
DATADIR = './data/'
In [7]:
train_df = pd.read_csv(DATADIR+"train.csv")
val_df = pd.read_csv(DATADIR+"val.csv")
test_df = pd.read_csv(DATADIR+"sample_submission.csv")
In [8]:
train_size = 10000
val_size = 4000
test_size = 10000
train = [f'{DATADIR}train/{i}.jpg' for i in train_df.ImageID]
val = [f'{DATADIR}val/{i}.jpg' for i in val_df.ImageID]
test = [f'{DATADIR}test/{i}.jpg' for i in test_df.ImageID]
train = train[:train_size]
val = val[:val_size]
In [9]:
mpimg.imread(test[0]).shape
Out[9]:
Function to extract FEN¶
In [10]:
def fen_from_filename(filename):
base = os.path.basename(filename)
image_id = int(os.path.splitext(base)[0])
#print(image_id)
fen = train_df.iloc[image_id].label
return fen
Examples:¶
In [11]:
print(fen_from_filename(train[0]))
print(fen_from_filename(train[1]))
print(fen_from_filename(train[2]))
Plotting samples¶
In [12]:
f, axarr = plt.subplots(1,3, figsize=(120, 120))
for i in range(0,3):
axarr[i].set_title(fen_from_filename(train[i]), fontsize=70, pad=30)
axarr[i].imshow(mpimg.imread(train[i]))
axarr[i].axis('off')