82 KiB
82 KiB
import numpy as np
import pandas as pd
import cv2
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Flatten, Dropout, Activation, Conv2D, MaxPooling2D
# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory
import os
print(os.listdir("Biedap/input"))
import zipfile
with zipfile.ZipFile("Biedap/input/train.zip","r") as z:
z.extractall(".")
with zipfile.ZipFile("Biedap/input/test1.zip","r") as z:
z.extractall(".")
# Any results you write to the current directory are saved as output.
2022-12-05 23:24:19.525108: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2022-12-05 23:24:19.670858: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/mosquito/anaconda3/lib/python3.9/site-packages/cv2/../../lib64: 2022-12-05 23:24:19.670876: I tensorflow/compiler/xla/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 2022-12-05 23:24:20.414074: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/mosquito/anaconda3/lib/python3.9/site-packages/cv2/../../lib64: 2022-12-05 23:24:20.414150: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/mosquito/anaconda3/lib/python3.9/site-packages/cv2/../../lib64: 2022-12-05 23:24:20.414157: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
main_dir = "Biedap"
train_dir = "train"
path = os.path.join(main_dir,train_dir)
for p in os.listdir(path):
category = p.split(".")[0]
img_array = cv2.imread(os.path.join(path,p),cv2.IMREAD_GRAYSCALE)
new_img_array = cv2.resize(img_array, dsize=(80, 80))
plt.imshow(new_img_array,cmap="gray")
break
X = []
y = []
convert = lambda category : int(category == 'dog')
def create_test_data(path):
for p in os.listdir(path):
category = p.split(".")[0]
category = convert(category)
img_array = cv2.imread(os.path.join(path,p),cv2.IMREAD_GRAYSCALE)
new_img_array = cv2.resize(img_array, dsize=(80, 80))
X.append(new_img_array)
y.append(category)
create_test_data(path)
X = np.array(X).reshape(-1, 80,80,1)
y = np.array(y)
X = X/255.0
model = Sequential()
# Adds a densely-connected layer with 64 units to the model:
model.add(Conv2D(64,(3,3), activation = 'relu', input_shape = X.shape[1:]))
model.add(MaxPooling2D(pool_size = (2,2)))
# Add another:
model.add(Conv2D(64,(3,3), activation = 'relu'))
model.add(MaxPooling2D(pool_size = (2,2)))
model.add(Flatten())
model.add(Dense(64, activation='relu'))
# Add a softmax layer with 10 output units:
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer="adam",
loss='binary_crossentropy',
metrics=['accuracy'])
2022-12-05 23:24:40.180280: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2022-12-05 23:24:40.180611: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/mosquito/anaconda3/lib/python3.9/site-packages/cv2/../../lib64: 2022-12-05 23:24:40.180666: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublas.so.11'; dlerror: libcublas.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/mosquito/anaconda3/lib/python3.9/site-packages/cv2/../../lib64: 2022-12-05 23:24:40.180712: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublasLt.so.11'; dlerror: libcublasLt.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/mosquito/anaconda3/lib/python3.9/site-packages/cv2/../../lib64: 2022-12-05 23:24:40.180764: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcufft.so.10'; dlerror: libcufft.so.10: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/mosquito/anaconda3/lib/python3.9/site-packages/cv2/../../lib64: 2022-12-05 23:24:40.180810: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcurand.so.10'; dlerror: libcurand.so.10: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/mosquito/anaconda3/lib/python3.9/site-packages/cv2/../../lib64: 2022-12-05 23:24:40.180855: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusolver.so.11'; dlerror: libcusolver.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/mosquito/anaconda3/lib/python3.9/site-packages/cv2/../../lib64: 2022-12-05 23:24:40.180898: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusparse.so.11'; dlerror: libcusparse.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/mosquito/anaconda3/lib/python3.9/site-packages/cv2/../../lib64: 2022-12-05 23:24:40.180943: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudnn.so.8'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/mosquito/anaconda3/lib/python3.9/site-packages/cv2/../../lib64: 2022-12-05 23:24:40.180951: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform. Skipping registering GPU devices... 2022-12-05 23:24:40.181384: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
model.fit(X, y, epochs=10, batch_size=32, validation_split=0.2)
Epoch 1/10 101/625 [===>..........................] - ETA: 1:04 - loss: 0.6977 - accuracy: 0.5309
[0;31m---------------------------------------------------------------------------[0m [0;31mKeyboardInterrupt[0m Traceback (most recent call last) Input [0;32mIn [7][0m, in [0;36m<cell line: 1>[0;34m()[0m [0;32m----> 1[0m [43mmodel[49m[38;5;241;43m.[39;49m[43mfit[49m[43m([49m[43mX[49m[43m,[49m[43m [49m[43my[49m[43m,[49m[43m [49m[43mepochs[49m[38;5;241;43m=[39;49m[38;5;241;43m10[39;49m[43m,[49m[43m [49m[43mbatch_size[49m[38;5;241;43m=[39;49m[38;5;241;43m32[39;49m[43m,[49m[43m [49m[43mvalidation_split[49m[38;5;241;43m=[39;49m[38;5;241;43m0.2[39;49m[43m)[49m File [0;32m~/anaconda3/lib/python3.9/site-packages/keras/utils/traceback_utils.py:65[0m, in [0;36mfilter_traceback.<locals>.error_handler[0;34m(*args, **kwargs)[0m [1;32m 63[0m filtered_tb [38;5;241m=[39m [38;5;28;01mNone[39;00m [1;32m 64[0m [38;5;28;01mtry[39;00m: [0;32m---> 65[0m [38;5;28;01mreturn[39;00m [43mfn[49m[43m([49m[38;5;241;43m*[39;49m[43margs[49m[43m,[49m[43m [49m[38;5;241;43m*[39;49m[38;5;241;43m*[39;49m[43mkwargs[49m[43m)[49m [1;32m 66[0m [38;5;28;01mexcept[39;00m [38;5;167;01mException[39;00m [38;5;28;01mas[39;00m e: [1;32m 67[0m filtered_tb [38;5;241m=[39m _process_traceback_frames(e[38;5;241m.[39m__traceback__) File [0;32m~/anaconda3/lib/python3.9/site-packages/keras/engine/training.py:1650[0m, in [0;36mModel.fit[0;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)[0m [1;32m 1642[0m [38;5;28;01mwith[39;00m tf[38;5;241m.[39mprofiler[38;5;241m.[39mexperimental[38;5;241m.[39mTrace( [1;32m 1643[0m [38;5;124m"[39m[38;5;124mtrain[39m[38;5;124m"[39m, [1;32m 1644[0m epoch_num[38;5;241m=[39mepoch, [0;32m (...)[0m [1;32m 1647[0m _r[38;5;241m=[39m[38;5;241m1[39m, [1;32m 1648[0m ): [1;32m 1649[0m callbacks[38;5;241m.[39mon_train_batch_begin(step) [0;32m-> 1650[0m tmp_logs [38;5;241m=[39m [38;5;28;43mself[39;49m[38;5;241;43m.[39;49m[43mtrain_function[49m[43m([49m[43miterator[49m[43m)[49m [1;32m 1651[0m [38;5;28;01mif[39;00m data_handler[38;5;241m.[39mshould_sync: [1;32m 1652[0m context[38;5;241m.[39masync_wait() File [0;32m~/anaconda3/lib/python3.9/site-packages/tensorflow/python/util/traceback_utils.py:150[0m, in [0;36mfilter_traceback.<locals>.error_handler[0;34m(*args, **kwargs)[0m [1;32m 148[0m filtered_tb [38;5;241m=[39m [38;5;28;01mNone[39;00m [1;32m 149[0m [38;5;28;01mtry[39;00m: [0;32m--> 150[0m [38;5;28;01mreturn[39;00m [43mfn[49m[43m([49m[38;5;241;43m*[39;49m[43margs[49m[43m,[49m[43m [49m[38;5;241;43m*[39;49m[38;5;241;43m*[39;49m[43mkwargs[49m[43m)[49m [1;32m 151[0m [38;5;28;01mexcept[39;00m [38;5;167;01mException[39;00m [38;5;28;01mas[39;00m e: [1;32m 152[0m filtered_tb [38;5;241m=[39m _process_traceback_frames(e[38;5;241m.[39m__traceback__) File [0;32m~/anaconda3/lib/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py:880[0m, in [0;36mFunction.__call__[0;34m(self, *args, **kwds)[0m [1;32m 877[0m compiler [38;5;241m=[39m [38;5;124m"[39m[38;5;124mxla[39m[38;5;124m"[39m [38;5;28;01mif[39;00m [38;5;28mself[39m[38;5;241m.[39m_jit_compile [38;5;28;01melse[39;00m [38;5;124m"[39m[38;5;124mnonXla[39m[38;5;124m"[39m [1;32m 879[0m [38;5;28;01mwith[39;00m OptionalXlaContext([38;5;28mself[39m[38;5;241m.[39m_jit_compile): [0;32m--> 880[0m result [38;5;241m=[39m [38;5;28;43mself[39;49m[38;5;241;43m.[39;49m[43m_call[49m[43m([49m[38;5;241;43m*[39;49m[43margs[49m[43m,[49m[43m [49m[38;5;241;43m*[39;49m[38;5;241;43m*[39;49m[43mkwds[49m[43m)[49m [1;32m 882[0m new_tracing_count [38;5;241m=[39m [38;5;28mself[39m[38;5;241m.[39mexperimental_get_tracing_count() [1;32m 883[0m without_tracing [38;5;241m=[39m (tracing_count [38;5;241m==[39m new_tracing_count) File [0;32m~/anaconda3/lib/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py:912[0m, in [0;36mFunction._call[0;34m(self, *args, **kwds)[0m [1;32m 909[0m [38;5;28mself[39m[38;5;241m.[39m_lock[38;5;241m.[39mrelease() [1;32m 910[0m [38;5;66;03m# In this case we have created variables on the first call, so we run the[39;00m [1;32m 911[0m [38;5;66;03m# defunned version which is guaranteed to never create variables.[39;00m [0;32m--> 912[0m [38;5;28;01mreturn[39;00m [38;5;28;43mself[39;49m[38;5;241;43m.[39;49m[43m_no_variable_creation_fn[49m[43m([49m[38;5;241;43m*[39;49m[43margs[49m[43m,[49m[43m [49m[38;5;241;43m*[39;49m[38;5;241;43m*[39;49m[43mkwds[49m[43m)[49m [38;5;66;03m# pylint: disable=not-callable[39;00m [1;32m 913[0m [38;5;28;01melif[39;00m [38;5;28mself[39m[38;5;241m.[39m_variable_creation_fn [38;5;129;01mis[39;00m [38;5;129;01mnot[39;00m [38;5;28;01mNone[39;00m: [1;32m 914[0m [38;5;66;03m# Release the lock early so that multiple threads can perform the call[39;00m [1;32m 915[0m [38;5;66;03m# in parallel.[39;00m [1;32m 916[0m [38;5;28mself[39m[38;5;241m.[39m_lock[38;5;241m.[39mrelease() File [0;32m~/anaconda3/lib/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compiler.py:134[0m, in [0;36mTracingCompiler.__call__[0;34m(self, *args, **kwargs)[0m [1;32m 131[0m [38;5;28;01mwith[39;00m [38;5;28mself[39m[38;5;241m.[39m_lock: [1;32m 132[0m (concrete_function, [1;32m 133[0m filtered_flat_args) [38;5;241m=[39m [38;5;28mself[39m[38;5;241m.[39m_maybe_define_function(args, kwargs) [0;32m--> 134[0m [38;5;28;01mreturn[39;00m [43mconcrete_function[49m[38;5;241;43m.[39;49m[43m_call_flat[49m[43m([49m [1;32m 135[0m [43m [49m[43mfiltered_flat_args[49m[43m,[49m[43m [49m[43mcaptured_inputs[49m[38;5;241;43m=[39;49m[43mconcrete_function[49m[38;5;241;43m.[39;49m[43mcaptured_inputs[49m[43m)[49m File [0;32m~/anaconda3/lib/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/monomorphic_function.py:1745[0m, in [0;36mConcreteFunction._call_flat[0;34m(self, args, captured_inputs, cancellation_manager)[0m [1;32m 1741[0m possible_gradient_type [38;5;241m=[39m gradients_util[38;5;241m.[39mPossibleTapeGradientTypes(args) [1;32m 1742[0m [38;5;28;01mif[39;00m (possible_gradient_type [38;5;241m==[39m gradients_util[38;5;241m.[39mPOSSIBLE_GRADIENT_TYPES_NONE [1;32m 1743[0m [38;5;129;01mand[39;00m executing_eagerly): [1;32m 1744[0m [38;5;66;03m# No tape is watching; skip to running the function.[39;00m [0;32m-> 1745[0m [38;5;28;01mreturn[39;00m [38;5;28mself[39m[38;5;241m.[39m_build_call_outputs([38;5;28;43mself[39;49m[38;5;241;43m.[39;49m[43m_inference_function[49m[38;5;241;43m.[39;49m[43mcall[49m[43m([49m [1;32m 1746[0m [43m [49m[43mctx[49m[43m,[49m[43m [49m[43margs[49m[43m,[49m[43m [49m[43mcancellation_manager[49m[38;5;241;43m=[39;49m[43mcancellation_manager[49m[43m)[49m) [1;32m 1747[0m forward_backward [38;5;241m=[39m [38;5;28mself[39m[38;5;241m.[39m_select_forward_and_backward_functions( [1;32m 1748[0m args, [1;32m 1749[0m possible_gradient_type, [1;32m 1750[0m executing_eagerly) [1;32m 1751[0m forward_function, args_with_tangents [38;5;241m=[39m forward_backward[38;5;241m.[39mforward() File [0;32m~/anaconda3/lib/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/monomorphic_function.py:378[0m, in [0;36m_EagerDefinedFunction.call[0;34m(self, ctx, args, cancellation_manager)[0m [1;32m 376[0m [38;5;28;01mwith[39;00m _InterpolateFunctionError([38;5;28mself[39m): [1;32m 377[0m [38;5;28;01mif[39;00m cancellation_manager [38;5;129;01mis[39;00m [38;5;28;01mNone[39;00m: [0;32m--> 378[0m outputs [38;5;241m=[39m [43mexecute[49m[38;5;241;43m.[39;49m[43mexecute[49m[43m([49m [1;32m 379[0m [43m [49m[38;5;28;43mstr[39;49m[43m([49m[38;5;28;43mself[39;49m[38;5;241;43m.[39;49m[43msignature[49m[38;5;241;43m.[39;49m[43mname[49m[43m)[49m[43m,[49m [1;32m 380[0m [43m [49m[43mnum_outputs[49m[38;5;241;43m=[39;49m[38;5;28;43mself[39;49m[38;5;241;43m.[39;49m[43m_num_outputs[49m[43m,[49m [1;32m 381[0m [43m [49m[43minputs[49m[38;5;241;43m=[39;49m[43margs[49m[43m,[49m [1;32m 382[0m [43m [49m[43mattrs[49m[38;5;241;43m=[39;49m[43mattrs[49m[43m,[49m [1;32m 383[0m [43m [49m[43mctx[49m[38;5;241;43m=[39;49m[43mctx[49m[43m)[49m [1;32m 384[0m [38;5;28;01melse[39;00m: [1;32m 385[0m outputs [38;5;241m=[39m execute[38;5;241m.[39mexecute_with_cancellation( [1;32m 386[0m [38;5;28mstr[39m([38;5;28mself[39m[38;5;241m.[39msignature[38;5;241m.[39mname), [1;32m 387[0m num_outputs[38;5;241m=[39m[38;5;28mself[39m[38;5;241m.[39m_num_outputs, [0;32m (...)[0m [1;32m 390[0m ctx[38;5;241m=[39mctx, [1;32m 391[0m cancellation_manager[38;5;241m=[39mcancellation_manager) File [0;32m~/anaconda3/lib/python3.9/site-packages/tensorflow/python/eager/execute.py:52[0m, in [0;36mquick_execute[0;34m(op_name, num_outputs, inputs, attrs, ctx, name)[0m [1;32m 50[0m [38;5;28;01mtry[39;00m: [1;32m 51[0m ctx[38;5;241m.[39mensure_initialized() [0;32m---> 52[0m tensors [38;5;241m=[39m [43mpywrap_tfe[49m[38;5;241;43m.[39;49m[43mTFE_Py_Execute[49m[43m([49m[43mctx[49m[38;5;241;43m.[39;49m[43m_handle[49m[43m,[49m[43m [49m[43mdevice_name[49m[43m,[49m[43m [49m[43mop_name[49m[43m,[49m [1;32m 53[0m [43m [49m[43minputs[49m[43m,[49m[43m [49m[43mattrs[49m[43m,[49m[43m [49m[43mnum_outputs[49m[43m)[49m [1;32m 54[0m [38;5;28;01mexcept[39;00m core[38;5;241m.[39m_NotOkStatusException [38;5;28;01mas[39;00m e: [1;32m 55[0m [38;5;28;01mif[39;00m name [38;5;129;01mis[39;00m [38;5;129;01mnot[39;00m [38;5;28;01mNone[39;00m: [0;31mKeyboardInterrupt[0m:
train_dir = "test1"
path = os.path.join(main_dir,train_dir)
#os.listdir(path)
X_test = []
id_line = []
def create_test1_data(path):
for p in os.listdir(path):
id_line.append(p.split(".")[0])
img_array = cv2.imread(os.path.join(path,p),cv2.IMREAD_GRAYSCALE)
new_img_array = cv2.resize(img_array, dsize=(80, 80))
X_test.append(new_img_array)
create_test1_data(path)
X_test = np.array(X_test).reshape(-1,80,80,1)
X_test = X_test/255
predictions = model.predict(X_test)
predicted_val = [int(round(p[0])) for p in predictions]
submission_df = pd.DataFrame({'id':id_line, 'label':predicted_val})
submission_df.to_csv("submission.csv", index=False)