Commit 918b014b authored by Kishore Bandi's avatar Kishore Bandi

Upload New File

parent 7d959fe0
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'loguru'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-3-116b189f71bb>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mcv2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mshutil\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mglob\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtqdm\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 5\u001b[1;33m \u001b[1;32mfrom\u001b[0m \u001b[0mloguru\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mlogger\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 6\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mpathlib\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mtensorflow\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mtf\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mModuleNotFoundError\u001b[0m: No module named 'loguru'"
]
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Defaulting to user installation because normal site-packages is not writeable\n",
"Requirement already satisfied: loguru in c:\\users\\nareshp\\appdata\\roaming\\python\\python37\\site-packages (0.4.1)\n",
"Requirement already satisfied: win32-setctime>=1.0.0 in c:\\users\\nareshp\\appdata\\roaming\\python\\python37\\site-packages (from loguru) (1.0.3)\n",
"Requirement already satisfied: colorama>=0.3.4 in c:\\users\\nareshp\\appdata\\roaming\\python\\python37\\site-packages (from loguru) (0.4.4)\n"
]
}
],
"source": [
"!pip install loguru"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import cv2,shutil\n",
"import glob, tqdm\n",
"# from loguru import logger\n",
"import pathlib\n",
"import tensorflow as tf\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n",
"\n",
"import os\n",
"os.environ['CUDA_VISIBLE_DEVICES']=''"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"Folder = './root/'\n",
"files = glob.glob(f'{Folder}*.jpg')\n",
"xmlfiles = glob.glob(f'{Folder}*.txt')\n",
"# logger.info(f'Total images in {Folder} are:{len(files)}')\n",
"# logger.info(f'Sample File: {np.random.choice(files)}')"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"# dest_file = 'C:/Users/raju/Documents/MLCervix/Data/STCOPY/'\n",
"# for file in files :\n",
"# shutil.copy2(file, dest_file, follow_symlinks=True)\n",
"# # shutil.move(file, dest_file)\n",
" \n",
"# print(file)\n",
"\n",
"# "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"100"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"train_ratio = 0.8\n",
"test_ratio = 0.2\n",
"\n",
"\n",
"#total count of imgs\n",
"totalImgCount = len(files)\n",
"totalImgCount"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"80 20\n"
]
}
],
"source": [
"#counting range for cycles\n",
"countForTrain = int(totalImgCount*train_ratio)\n",
"countForTest = int(totalImgCount*test_ratio)\n",
"print(countForTrain,countForTest)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# for x in range(2):\n",
"# filename=files[x].split('\\\\',1)[1].split('.')[0]\n",
"# cofile=filename+'.xml'\n",
"# for k in xmlfiles:\n",
"# if k==filename :\n",
"# print(k)\n",
"# f=files[x]\n",
"# print(k,f,x)\n",
" \n",
"# shutil.move(file, dest_file)\n",
"# shutil.move(cofile, dest_file)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"./root\\6fc13bda-6f8c-11eb-b534-a9951b0b6835_12_ST_low_ac_HSIL_T1_S8.txt ./root\\5da29ef4-6f96-11eb-ac34-a9951b0b6835_19_ST_high_iod_T3_S2_LSIL.jpg 79\n"
]
}
],
"source": [
"#cycle for Train dir\n",
"dest_file = './Train'\n",
"for x in range(countForTrain):\n",
" if glob.glob(files[x]) :\n",
" filename=files[x].split('\\\\',1)[1].split('.')[0]\n",
" cofile=filename+'.txt'\n",
" shutil.move(files[x], dest_file)\n",
" for k in xmlfiles:\n",
" if glob.glob(xmlfiles[x]) :\n",
" if k.split('\\\\',1)[1].split('.')[0]==filename :\n",
" shutil.move(k, dest_file)\n",
"print(k,files[x],x)\n"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"C:/Users/raju/Documents/MLCervix/Data/ImagesWithLabels\\ST 95 low raw T3 S0 Normal HPV 16.xml C:/Users/raju/Documents/MLCervix/Data/ImagesWithLabels\\123 ST low iod T2 S8.jpg 142\n"
]
}
],
"source": [
"#cycle for Train dir\n",
"dest_file = ''\n",
"for x in range(countForTest):\n",
" if glob.glob(files[x]) :\n",
" filename=files[x].split('\\\\',1)[1].split('.')[0]\n",
" cofile=filename+'.xml'\n",
" shutil.move(files[x], dest_file)\n",
" for k in xmlfiles:\n",
" if glob.glob(xmlfiles[x]) :\n",
" if k.split('\\\\',1)[1].split('.')[0]==filename :\n",
" shutil.move(k, dest_file)\n",
"print(k,files[x],x)\n"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"ename": "IndentationError",
"evalue": "expected an indented block (<ipython-input-30-d11ed62603ab>, line 4)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-30-d11ed62603ab>\"\u001b[1;36m, line \u001b[1;32m4\u001b[0m\n\u001b[1;33m if glob.glob(files[x]) :\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n"
]
}
],
"source": [
"# #cycle for Test dir\n",
"# dest_file = 'C:/Users/raju/Documents/MLCervix/Data/ImagesWithLabels/Test/'\n",
"# for x in range(countForTest):\n",
"# if glob.glob(files[x]) :\n",
" \n",
"# filename=files[x].split('\\\\',1)[1].split('.')[0]\n",
"# cofile=filename+'.xml'\n",
"# shutil.move(files[x], dest_file)\n",
"# for k in xmlfiles:\n",
"# if glob.glob(xmlfiles[x]) :\n",
" \n",
"# if k.split('\\\\',1)[1].split('.')[0]==filename :\n",
" \n",
"# shutil.move(k, dest_file)\n",
"# print(k,files[x],x)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment