{"id":24300555,"url":"https://github.com/iparsw/custom-intent","last_synced_at":"2025-09-26T02:31:45.795Z","repository":{"id":65204762,"uuid":"583296491","full_name":"iparsw/custom-intent","owner":"iparsw","description":"create chatbots, image classification and linear regression models with three lines of code you can install it by running pip install CustomIntents","archived":false,"fork":false,"pushed_at":"2023-06-15T23:04:02.000Z","size":4410,"stargazers_count":8,"open_issues_count":3,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-15T13:39:10.533Z","etag":null,"topics":["chatbot","chatbots","deep-learning","deep-neural-networks","deeplearning","image-classification","linear-regression","machine-learning","ml","python","python-library","python3","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iparsw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-29T10:59:42.000Z","updated_at":"2024-12-12T16:39:34.000Z","dependencies_parsed_at":"2024-11-15T07:27:34.317Z","dependency_job_id":"3991a8c1-67ec-4134-91a9-5026b6a6b7f8","html_url":"https://github.com/iparsw/custom-intent","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iparsw%2Fcustom-intent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iparsw%2Fcustom-intent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iparsw%2Fcustom-intent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iparsw%2Fcustom-intent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iparsw","download_url":"https://codeload.github.com/iparsw/custom-intent/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234174835,"owners_count":18791291,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatbot","chatbots","deep-learning","deep-neural-networks","deeplearning","image-classification","linear-regression","machine-learning","ml","python","python-library","python3","tensorflow"],"created_at":"2025-01-16T23:14:38.304Z","updated_at":"2025-09-26T02:31:40.314Z","avatar_url":"https://github.com/iparsw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Custom Intents\n\nV1.0.0\n\n(it's still a bit buggy)\n\n## a simple way to create chatbots Ai, image classification Ai, image generation Ai, image supper resolution Ai and more!!\n\n# installation\n\nyou can install the package from pypi (pip)\n\n```commandline\npip install CustomIntents\n```\n\n## examples\n\n![Demo1](images/img2.png)\n\n![Demo2](images/img.png)\n\n\n\nA package build on top of keras for creating and training deep learning chatbots (text classification), image classification, image generation Ai, image super resolution, style transforming and linear regression models in just three lines of code \n\nthe package is inspired by NeuralNine, neuralintents package a packege that let you build chatbot models with 3 lines of code\n\n# list of features:\n* [SuperRes class](#superres-class)\n* [ImageGenerator class](#imagegenerator-class)\n* [ChatBot class](#chatbot-class)\n* [JsonIntents](#jsonintents-class)\n* [ImageClassificator class](#imageclassificator-class)\n* [StyleTransformer class](#styletransformer-class)\n* [BinaryImageClassificator](#binaryimageclassificator-class)\n* [PLinearRegression class](#plinearregression-class)\n* [scanner moudule](#scanner-moudule)\n\n# SuperRes class\n\n## Init arguments\n```python\ndef __init__(self, input_size: tuple = (300, 300),\n             upscale_factor: int = 3,\n             cpu_only: bool = False):\n```\n\ninput_size : this is only required when training or finetuning\n\nupscale_factor : the upscale factor\n\ncpu_only : whether to use only CPU or not\n\n## upscale_image method\n```python\ndef upscale_image(self, img,\n                  save_name: str = None,\n                  save_image: bool = True):\n```\nimg : the image you want to upscale\n\nsave_image : whether to save the image\n\nsave_name : the name of the saved file\n\n## upscale_image_from_path method\n```python\ndef upscale_image_from_path(self, img_path,\n                            save_name: str = None,\n                            save_image: bool = True)\n```\nits like upscale_image method except that it requires a path to the image\n\n## load_training_data method\n```python\ndef load_training_data(self, dataset_path: str,\n                       validation_split: float = 0.2,\n                       batch_size: int = 8)\n```\ndataset_path : path to the training and validation data directory\n\nvalidation_split : a float between 0 and 1 where the validation split is specified\n\nbatch_size : batch size\n\n## train method\n```python\ndef train(self, lr: float = 0.001,\n          optimizer: str = \"Adam\",\n          epochs: int = 50,\n          ESPCNCallback_usage: bool = True,\n          ESPCNCallback_test_path: str = \"test\",\n          epoch_per_psnr: int = 20,\n          psnr_plot: bool = True,\n          model_type: str = \"xs1\",\n          loss_fns: list = None,\n          loss_fns_weight: list = None):\n```\noptimizer : name of the optimizer (corently supported optimizers are : Adam, Adagrad, Adamax, Adadelta, SGD, RMSprop, Nadam)\n\nepochs : number of epochs to train\n\nESPCNCallback_usage : wether to use ESPCNCallback or not\n\nESPCNCallback_test_path : a path to the test data directory for ESPCNCallback\n\nepoch_per_psnr : if you use ESPCNCallback it will show a sample every few epochs you can choose that number here\n\npsnr_plot : if you use ESPCNCall you can turn plutting a sample off\n\nmodel_type : the type of the model (there are some different types in this package but for now i recommend using using the diffault xs1)\n\nloss_fns : a list containing loss functions you want to use if you want only one loss function to use you can pass a list with only on loss functions \n\n(corently supported loss functions are : mse, mae, mape, ssim, psnr, ipcusl (this is a custom loss function for more information read IPCUSL.md), charbonnier, tv (total variation), tvd (total variation difference))\n\nloss_fns_weight : if you use multiple loss functions the model will calculate their weighted sum and this is a list that contains their sum in this order (mse,mae,mape,ssim,psnr,ipcusl,charbonnier,tv,tvd)\n\n## fine_tuning method\n```python\ndef fine_tuning(self, lr: float = 0.001,\n                epochs: int = 50,\n                model_name: str = \"super_res\",\n                ESPCNCallback_usage: bool = True,\n                ESPCNCallback_test_path: str = \"test\",\n                epoch_per_psnr: int = 20,\n                psnr_plot: bool = True,\n                recompile: bool = False,\n                optimizer: str = None,\n                loss_fns: list = None,\n                loss_fns_weight: list = None)\n```\nits almost equivalent to the train method except you should load a model first\n\n## load_model method\n\n```python\ndef load_model(self, model_name: str = \"super_res\")\n```\n\nmodel_name : the name of the model\n\n## save_model method\n\n```python\ndef save_model(self, model_name: str = \"super_res\")\n```\n\nmodel_name : the name of the model\n\n## benchmark method\n\n```python\ndef benchmark(self, image_path: str = \"testimage.jpg\",\n              input_size: tuple = (300, 300))\n```\n\nthis method will benchmark the model based on a single image\n\ninput_size : the image will be resized to the given size image and then upscaled by model\n\n## benchmark_from_directory method\n\n```python\ndef benchmark_from_directory(self, image_directory_path: str = \"test\",\n                             input_size: tuple = None)\n```\n\nthis method will benchmark the model based on a directory of images\n\ninput_size : the image will be resized to the given size image and then upscaled by model\n\n## example of training a model\n```python\nfrom CustomIntents import SuperRes\n\nmodel = SuperRes(input_size=(300, 300), upscale_factor=3)\nmodel.load_training_data(dataset_path=\"dataset\", batch_size=8)\nmodel.train(epochs=5, model_type=\"xs1\", psnr_plot=True, loss_fns=[\"IPCUSL\"], epoch_per_psnr=4)\n```\n## example of fine tuning a model\n```python\nfrom CustomIntents import SuperRes\n\nmodel = SuperRes(input_size=(100, 100), upscale_factor=3)\nmodel.load_training_data(dataset_path=\"dataset\", batch_size=32)\nmodel.fine_tuning(epochs=2, lr=0.00008, model_name=\"CSR3X-1.1.3\", psnr_plot=False, loss_fns=[\"mse\", \"mae\"])\n```\n## example of using the model to generate upscaled images\n```python\nfrom CustomIntents import SuperRes\n\nmodel = SuperRes(input_size=(300, 300), upscale_factor=3)\nmodel.load_model(\"CSR3X-1.1.2\")\nmodel.upscale_image_from_path(img_path=\"test_image_2_300x300.jpg\", save_name=\"test_result_300x300_to_900x900_7.jpg\")\n```\n\n## image example\n![DemoSuperRes](images/superres2.jpg)\n\n\n# ImageGenerator class\nyou can easily use state of the art StableDiffiusion model with this class\n\n## Init arguments\n```python\ndef __init__(self, *,\n             model: str = \"StableDiffusion\",\n             img_height: int = 256,\n             img_width: int = 256,\n             jit_compile: bool = False,\n             cpu_only: bool = False):\n```\n\nmodel : for now only StableDiffusion is available\n\nimg_height : it's the height of the genarated image it should be a multiple of 128\n\nimg_width : it's the width of the genarated image it should be a multiple of 128\n\njit_comple : it's a boolean indicating using just in time compliling\n\ncpu_only : it's a boolean indicating whether to use CPU only or GPU\n\nnote every argument should be passed as an keyword argument\n\n## generate method\n\n```python\ndef generate(self, *,\n             prompt: str = \"Iron man making breakfast\",\n             batch_size: int = 1,\n             filename: str = \"sample\",\n             num_steps: int = 50):\n```\n\nprompt : it's the prompt to create the image from\n\nbatch_size : how many of images to create\n\nfilename : the name of file to save\n\nnum_steps : the number of steps to run the image through the model bigger the number it will generate better images but also it will take longer to generate\n\n## gradio_preview method\n\nthis method will create a gradio preview\n\n this method doesn't get any arguments\n\n## examples of using this class \n\n### creating a gradio preview\n\n```python\nfrom CustomIntents import ImageGenerator\n\nmodel = ImageGenerator(model=\"StableDiffusion\",\n                       img_width=512,\n                       img_height=512,\n                       cpu_only=True,\n                       jit_compile=True)\n\nmodel.gradio_preview()\n```\n\n### generating an image\n\nthis code will generate two images and save them as \"a sample image.jpg\"  \n\n```python\nfrom ImageGenerator import ImageGenerator\n\nmodel = ImageGenerator(model=\"StableDiffusion\",\n                       img_width=512,\n                       img_height=512,\n                       cpu_only=True,\n                       jit_compile=True)\n\nmodel.generate(prompt=\"a cat lying on a bed\",\n               batch_size=2,\n               filename=\"a sample image\",\n               num_steps=50)\n```\n\n### Setting Up A Basic Chatbot\n\n```python\nfrom CustomIntents import ChatBot\nchatbot = ChatBot(model_name=\"test_model\", intents=\"intents.json\")\nassistant.train_model()\nassistant.save_model()\ndone = False\nwhile not done:\n    message = input(\"Enter a message: \")\n    if message == \"STOP\":\n        done = True\n    else:\n        assistant.request(message)\n```\n\n### Binding Functions To Requests\n\nthis is inspired by neuralintents\n\n```python\nfrom CustomIntents import ChatBot\ndef function_for_greetings():\n    print(\"You triggered the greetings intent!\")\n    # Some action you want to take\ndef function_for_stocks():\n    print(\"You triggered the stocks intent!\")\n    # Some action you want to take\nmappings = {'greeting' : function_for_greetings, 'stocks' : function_for_stocks}\nassistant = ChatBot('intents.json', intent_methods=mappings ,model_name=\"test_model\")\nassistant.train_model()\nassistant.save_model()\ndone = False\nwhile not done:\n    message = input(\"Enter a message: \")\n    if message == \"STOP\":\n        done = True\n    else:\n        assistant.request(message)\n```\n### Sample intents.json File\n```json\n{\"intents\": [\n  {\"tag\": \"greeting\",\n    \"patterns\": [\"Hi\", \"Salam\", \"Nice to meet you\", \"Hello\", \"Good day\", \"Hey\", \"greetings\"],\n    \"responses\": [\"Hello!\", \"Good to see you again!\", \"Hi there, how can I help?\"]\n  },\n  {\"tag\": \"goodbye\",\n    \"patterns\": [\"bye\", \"good bye\", \"see you later\"],\n    \"responses\": [\"bye\", \"good bye\"],\n    \"context_set\": \"\"\n  },\n  {\"tag\": \"something\",\n    \"patterns\": [\"something\", \"something else\", \"etc\"],\n    \"responses\": [\"the response to something\"],\n  }\n]\n}\n```\n\n# ChatBot Class\n\nthe first class in CustomIntent package is ChatBot\nits exacly what you thing a chatbot\n\n## Init arguaments\n\n```python\ndef __init__(self, intents, intent_methods, model_name=\"assistant_model\", threshold=0.25, w_and_b=False,\n             tensorboard=False):\n```\nintents : its the path of your intents file\n\nintents_method : its a dictionary of mapped functions\n\nmodel_name : its just the name of your model\n\nthreshold : its the accuracy threshold of your model its set to 0.25 by default\n\nw_and_b : it will connect to wandb if set to True (you will need to login first)\n\ntensorboard : Not available at the time\n\n## Training\n\nyou can start training your model with one function call train_model\n\ntraining model arguments :\n```python\ndef train_model(self, epoch=None, batch_size=5, learning_rate=None,\n                ignore_letters=None, timeIt=True, model_type='s1',\n                validation_split=0, optimizer=None, accuracy_and_loss_plot=True):\n```\n\nepoch: An epoch refers to one cycle of training the neural network with all the training data. This argument specifies the number of cycles that the network will undergo.\n\nbatch_size: An integer or None. This determines the number of samples per gradient update. You can ignore this argument if you like.\n\nlearning_rate: The learning rate is a hyper-parameter that controls the weights of the neural network with respect to the loss gradient. It defines how quickly the network updates the concepts it has learned. In simple terms, a larger learning rate makes the model learn faster but it can also deviate from the correct path more easily.\n\nignore_letters: A list of letters that you want to ignore. By default, it ignores the characters (? . , !). You can pass an empty list if you don't want to ignore any characters.\n\ntimeIt: This argument times the training process.\n\nmodel_type: You can select one of the predefined models (which will be described later).\n\nvalidation_split: You can split a portion of your data for validation only, meaning the model will not be trained on these samples. This argument should be a float between 0 and 1. I recommend not creating a validation split unless you have a very large dataset with many similar patterns.\n\noptimizer: You can choose between SGD, Adam, Adamx, and Adagard.\n\n## save_model\n\nit will save your model as two .pkl files and a .h5 file (don't add .h5 or .pkl)\n\n```python\ndef save_model(self, model_name=None):\n```\n\nmodel_name : if its None (defualt), it will save the files like (model_name.h5)(model_name_words.pkl)(model_name_classes.pkl) where the model_name is the name you specified in the first place\n\n## load_model\n\nit will load a model from those three files\n\n```python\ndef load_model(self, model_name=None):\n```\n\nmodel_name : if its None (defualt), it will look for files like (model_name.h5)(model_name_words.pkl)(model_name_classes.pkl) where the model_name is the name you specified in the first place\n\n## request_tag\n\nyou will pass it a massege and it will return the predicted tag for you\n\n```python\ndef request_tag(self, message, debug_mode=False, threshold=None):\n```\n\nmessage : the actual message\n\ndebug_mode : it will print every step of the procces for debuging perpes\n\nthreshold : you can set a accuracy threshold if not specified it will use the threshold you set when initilizing the bot and if you didn't specified there either it is set to 0.25 by default\n\n## request_response\n\nthe same as request_tag but it will return a random response from intents\n\n```python\ndef request_response(self, message, debug_mode=False, threshold=None):\n```\n\n## gradio_preview\n\nit will open up a nice gui for testing your model in your browser\n\n```python\ndef gradio_preview(self, ask_for_threshold=False, share=False, inbrowser=True):\n```\n\nask_for_threshold : if set to True it will create a slider that you can set the threshold of the model with it\n\nshare : if set to True it will make the demo public\n\ninbrowser : it will aoutomaticlly open a new browser page if set to True\n\n![Demo](images/img.png)\n\n## cli_preview\n\n```python\ndef cli_preview(self):\n```\n\na simple cli interface for testing your model\n\n## gui_preview\n\na custom gui for triyng or even deploying your model\n\n```python\ndef gui_preview(self, user_name=\"\"):\n```\n\nuser_name : it will only say hello to you if you pass your name for now\n\n![Demo](images/img2.png)\n\n## model types\n\nyou can choose one of the defined models according to the size of diffrente patterns and tags you have (you can just try and see wich one is right for your use case)\n\nxs1 : a very fast and small model\n\nxs2 : still small but better for more tags\n\n\ns1 : the default model (hidden layers : 128-64)\n\ns2 : its better than s1 when you have small number of similar tags that s1 cant predict\n\ns3 : most of the time you dont need this (hidden layers : 128-64-64)\n\ns4 : its like a s2 on streoid its suited when you have a lot of patterns for tags that have similar patterns\n\ns5 : most of the time you dont need this either (hidden layers : 128-64-64-32)\n\n\nm1 : great balance of perfomance and accuracy for medium size intent files\n\nm2 : great accuracy for medium size intent files\n\nm3 : m3 to m1 is like s2 to s1 its more suited when you have smaller number of tags but hard to difrentiat\n\nl1 - l2 - l3 - l4 - l5 - xl1 - xl2 - xl3 - xl5 : are bigger models for more information read MODELS.md\n\n# JsonIntents Class\n\nthis class is used to add and edit Json files containing intents\n```python\ndef __init__(self, json_file_adrees):\n```\n\nyou just need to pass the path of the json file the function you want\n\n## add_pattern_app\n\nits a function that ask you to input new patterns for tags (you can pass an especific tag to ask for that or it will cycle through them all and will go to the next tag by inputing D or d)\n\n```python\ndef add_pattern_app(self, tag=None):\n```\n\n## add_tag_app\n\nit will add new tags to your json file \n\n```python\ndef add_tag_app(self, tag=None, responses=None):\n```\ntag : the name of the new tag you want to add\n\nresponses : a list of responses (you can add later on as well)\n\n## delete_duplicate_app\n\nit will check for duplicate in patterns and deletes them for you\n\n## an example of using this class\n\n```python\nfile = JsonIntents(\"internet intents.json\")\nfile.delete_duplicate_app()\nfile.add_tag_app(tag=\"about\")\nfile.add_pattern_app(\"about\")\n```\n\n# ImageClassificator class\n\nthe seccond class in CustomIntent package is ImageClassificator\nit let you create and train deep learning image classification models with just three line of code !!\n\n## init arguments\n```python\ndef __init__(self, data_folder=\"data\",\n                 model_name=\"imageclassification_model\",\n                 number_of_classes=2,\n                 classes_name=None,\n                 gpu=None, \n                 checkpoint_filepath='/tmp/checkpoint_epoch:{epoch}'):\n```\n\ndata_folder : the path to where you located your data\n\nmodel_name : name your model\n\nnumber_of_classes : number of difrent classes you have in your data (you should put the pictures of every class in a sub folder in your data folder)\n\nclasses_name : a list of names correspunding to your classes (they should be the same as the folder name of correspunding data folder for example if you have 3 sub folder in your data folder as banana apple pineapple you should pass [\"banana\", \"apple\", \"pineapple\"])\n\ngpu : you can pass True or False if you dont pass anything it will try to use your gpu if you have a cuda enaibled graphic card and you have cudatoolkit and cuDNN installed and if you dont it will use your cpu\n\ncheckpoint_filepath : path to where you want your checkpoints\n\n## Training\n\nyou can start training your model with one function call train_model\n\ntraining model arguments :\n```python\ndef train_model(self, epochs=20,\n                    model_type=\"s1\",\n                    logdir=None,\n                    optimizer_type=\"adam\",\n                    learning_rate=0.00001,\n                    class_weight=None,\n                    prefetching=False,\n                    plot_model=True,\n                    validation_split=0.2,\n                    test_split=0,\n                    augment_data=False,\n                    tensorboard_usage=False,\n                    stop_early=False,\n                    checkpoint=False):\n```\n\nepoch : an epoch basicly means training the neural network with all the training data for one cycle and this arguament says how many of this circles it will go\n\nmodel_type : you can select one of the defined models (we will look at the available models later on)\n\nlogdir : a directory to hold your tensorboard log files you can leave is empty if you dont care\n\noptimizer_type : you can only choose adam right now\n\nlearning_rate : Learning rate is a hyper-parameter that controls the weights of our neural network with respect to the loss gradient. It defines how quickly the neural network updates the concepts it has learned. (in simple terms if its bigger our model learn faster but it can go of track faster)\n\nclass_weight : if you have an unbalanced dataset you can path a dictionary with the weight that you what to assosiate with every class () \n\nprefetching : prefetching data\n\nplot_model : it will plot the model architecture for you \n\nvalidation_split : you can split a portion of your data for validation only (model will not get trained on them) it should be float between 0 and 1 (i will recommend to not create a validation split unless you have a really huge data set with lots of similar patterns)\n\naugment_data : if set to true the model will also be trained on augmented data \n\ntensorboard_usage : it will use tensorboard\n\nstop_early : if set to true it will stop training if validation loss is the same or increasing for more than 5 epochs\n\ncheckpoint : if set to true it will save checkpoints if the validation loss is the lovest ever seen\n\n## save_model\n\nit will save your model a .h5 file\n\n```python\ndef save_model(self, model_file_name=None):\n```\n\nmodel_name : if its None (defualt), it will save the files like (model_name.h5) where the model_name is the name you specified in the first place\n\n## load_model\n\nit will load a model from those three files\n\n```python\ndef load_model(self, name=\"imageclassification_model\"):\n```\n\nmodel_name : if its None (defualt), it will look for files like (imageclassification_model.h5) \n\n## predict\n\nnow you can predict \n\n```python\ndef predict(self, image, image_type=None, full_mode=False, accuracy=False):\n```\n\nimage : a path to an image file or a numpy array of the image or a cv2 image\n\nimage_type : if its None (defualt), it will try to detect if the image is a cv2 image or a numpy array of the image or a path to the image\n\nfull_mode : if you set it to true it will return every class and its probability\n\naccuracy : if you set it to true it will return a tuple of the class name and the probability\n\n(if both full_mode and accuracy set to false (defualt behavier) it will just return the most likly class name)\n\n## predict_face\n\n```python\n    def predict_face(self, img, image_type=None, full_mode=False,\n                     accuracy=False, return_picture=False,\n                     save_returned_picture=False, saved_returned_picture_name=\"test.jpg\",\n                     show_returned_picture=False):\n```\n\nimg : a path to an image file or a numpy array of the image or a cv2 image\n\nimage_type : if its None (defualt), it will try to detect if the image is a cv2 image or a numpy array of the image or a path to the image\n\nfull_mode : if you set it to true it will return every class and its probability\n\naccuracy : if you set it to true it will return a tuple of the class name and the probability\n\nreturn_picture : if set to true it will return a picture with faces in rectangles and their predicted class writen on top of them\n\nsave_returned_picture : if set to True it will save the returned picture\n\nsaved_returned_picture_name : if you set save_returned_picture to true you can use this to especifie the name of the saved picture\n\nshow_returned_picture : if set to true it will open the returned picture in a cv2 preview\n\n## realtime_prediction\n\n```python\ndef realtime_prediction(self, src=0):\n```\n\nsrc : if you have multiple webcams or virtual webcams it will let you choose from them if you only have one live it empty\n\n## realtime face prediction\n\nits exacly like the realtime_prediction() method but it will detect facec with a haarcascadde and will feed the model with the facec to predict\n\n```python\ndef realtime_face_prediction(self, src=0, frame_rate=5):\n```\n\nsrc : if you have multiple webcams or virtual webcams it will let you choose from them if you only have one live it empty\n\nframe_rate : its the number of frames to skip before predicting again\n\n\n## gradio_preview\n\nit will open up a nice gui for testing your model in your browser\n\n```python\ndef gradio_preview(self, share=False, inbrowser=True, predict_face=False):\n```\n\nshare : if set to True it will make the demo public\n\ninbrowser : it will aoutomaticlly open a new browser page if set to True\n\npredict_face : if set to True it will look for faces and feed them to the model \n\n## example of using ImageClassificator\n\nin this example i have a folder in data/full that contains 4 sub folders (beni, khodm, matin, parsa) and in every one of them i have a lot of pictures of my friends (the folder name corredpunds to their names for example in beni folder there are beni's pictures, btw khodm means myself in my languge) and i want to train a model to detect which one of us we are in the picture\n\n```python\nfrom CustomIntents import ImageClassificator\n\nmodel = ImageClassificator(model_name=\"test_m1\", data_folder=\"data/full\", number_of_classes=4, classes_name=[\"beni\", \"khodm\", \"matin\", \"parsa\"])\nmodel.train_model(epochs=10, model_type=\"m1\", logdir=\"logs\", learning_rate=0.0001, prefetching=False)\nmodel.save_model(model_file_name=\"test_m1\")\n```\n```python\nfrom CustomIntents import BinaryImageClassificator\n\nmodel = ImageClassificator(model_name=\"test_m1\", data_folder=\"data/full\", number_of_classes=4, classes_name=[\"beni\", \"khodm\", \"matin\", \"parsa\"])\nmodel.load_model(name=\"test_m1\")\nresult = model.realtime_face_prediction()\n```\n![Demo3](images/realtime_prediction_example.png)\nand as you see in the picture above you can see it under the that it is me in the picture with a really high accuracy\n\n# StyleTransformer class\n\nthe fourth class in CustomIntent package is StyleTransformer\nit let you transform an image to the style of another image\n\n![Demo3](images/style_transformer.png)\n\n## init arguments\n\n```python\ndef __init__(self, image_path=None,\n             style_reference_image_path=None,\n             result_prefix=\"test_generated\"):\n```\n\nimage path : the path to the original image\n\nstyle_reference_image_path : the path to the style reference image\n\nresult_prefix : the prefix for the result file\n\n## transform method\n\nthe main method of this class\n\n```python\ndef transfer(self, iterations=4000, iteration_per_save=100):\n```\n\niterations : the number of iterations\n\niteration_per_save : save every _ iteration (where _ is the number you pass)\n\n## gradio_preview method\n\na browser based app to use this class\n\n```python\ndef gradio_preview(self, share=False, inbrowser=True):\n```\n\nshare : if set to True it will make the demo public\n\ninbrowser : it will aoutomaticlly open a new browser page if set to True\n\n## example of using StyleTransformer\n\n### passing the path of base and reference image\n\n```python\nfrom CustomIntents import StyleTransformer\n\nmodel = StyleTransformer(image_path=\"base_image.jpg\", style_reference_image_path=\"style_reference_image.jpg\")\nmodel.transfer(iterations=500, iteration_per_save=50)\n```\n\nthis code will perform the teransformation for 500 times and save them every 50 steps\n\n### Using gradio preview\n\n```python\nfrom CustomIntents import StyleTransformer\n\nmodel = StyleTransformer()\nmodel.gradio_preview()\n```\n![Demo3](images/dtyleTransformer_gradio.png)\n\n#### *this model is slow so use reasonable iteration counts\ndon't use ridiculous numbers like 4000 like me, it took about 15 minutes on a 1660ti\n\n# BinaryImageClassificator class\n\nthe fourth class in CustomIntent package is BinaryImageClassificator\nit let you create and train deep learning image classification models with just three line of code !!\n\n## Init arguaments\n\n```python\ndef __init__(self, data_folder=\"data\", model_name=\"imageclassification_model\",\n             first_class=\"1\", second_class=\"2\"):\n```\n\ndata_folder : it's the path of your data folder (you should put your training images in two subfolder representing their label (class))\n\nmodel_name : your model's name\n\nfirst_class : you can name your classes so when you whant to predict it returns their name insted of 1s and 2s\n\nseccond_class : //\n\n## Training\n\nyou can start training your model with one function call train_model\n\ntraining model arguments :\n```python\ndef train_model(self, epochs=20, model_type=\"s1\", logdir=None,\n                optimizer_type=\"adam\", learning_rate=0.00001,\n                class_weight=None, prefetching=False, plot_model=True,\n                validation_split=0.2):\n```\n\nepoch : an epoch basicly means training the neural network with all the training data for one cycle and this arguament says how many of this circles it will go\n\nmodel_type : you can select one of the defined models (read MODELS.md for more information)\n\nlogdir : a directory to hold your tensorboard log files you can leave is empty if you don't care\n\noptimizer_type : you can only choose adam right now\n\nlearning_rate : Learning rate is a hyper-parameter that controls the weights of our neural network with respect to the loss gradient. It defines how quickly the neural network updates the concepts it has learned. (in simple terms if its bigger our model learn faster but it can go of track faster)\n\nclass_weight : if you have an unbalanced dataset you can path a dictionary with the weight that you what to assosiate with every class () \n\nprefetching : prefetching data\n\nplot_model : it will plot the model architecture for you \n\nvalidation_split : you can split a portion of your data for validation only (model will not get trained on them) it should be float between 0 and 1 (i will recommend to not create a validation split unless you have a really huge data set with lots of similar patterns)\n\n## save_model\n\nit will save your model a .h5 file (don't add .h5)\n\n```python\ndef save_model(self, model_file_name=None):\n```\n\nmodel_name : if its None (defualt), it will save the files like (model_name.h5) where the model_name is the name you specified in the first place\n\n## load_model\n\nit will load a model from those three files\n\n```python\ndef load_model(self, name=\"imageclassification_model\"):\n```\n\nmodel_name : if its None (defualt), it will look for files like (imageclassification_model.h5) \n\n## predict\n\nnow you can predict \n\n```python\ndef predict(self, image, image_type=None, accuracy=False):\n```\n\nimage : a path to an image file or a numpy array of the image or a cv2 image\n\nimage_type : if its None (defualt), it will it will try to detect if the image is a cv2 image or a numpy array of the image or a path to the image\n\naccuracy : if you set it to true it will return a tuple of the class name and the probability\n\n\n## predict from file path (legacy)\n\nit will predict what class the image blongs to from a path\n\n```python\ndef predict_from_files_path(self, image_file_path):\n```\n\nimage_file_path : the path of the image you want to predict\n\nit will return the name of the class and the percentage that its correct\n\n## predict from imshow (legacy)\n\nit will predict what class the image blongs to from a cv2 object\n\n```python\ndef predict_from_imshow(self, img):\n```\n\nimg : a cv2 image object \n\nit will return the name of the class and the percentage that its correct\n\n## realtime prediction\n\nit will predict from a live video feed (it will open a live cv2 video feed)\n\n```python\ndef realtime_prediction(self, src=0):\n```\n\nsrc : if you have multiple webcams or virtual webcams it will let you choose from them if you only have one live it empty\n\n## realtime face prediction\n\nits exacly like the realtime_prediction() method but it will detect facec with a haarcascadde and will feed the model with the facec to predict\n\n```python\ndef realtime_face_prediction(self, src=0):\n```\n\nsrc : if you have multiple webcams or virtual webcams it will let you choose from them if you only have one live it empty\n\n## gradio_preview\n\nit will open up a nice gui for testing your model in your browser\n\n```python\ndef gradio_preview(self, share=False, inbrowser=True):\n```\n\nshare : if set to True it will make the demo public\n\ninbrowser : it will aoutomaticlly open a new browser page if set to True\n\n## example of using BinaryImageClassificator\n\n```python\nfrom CustomIntents import BinaryImageClassificator\n\nmodel = BinaryImageClassificator(model_name=\"test1\", data_folder=\"data/parsa\", first_class=\"sad\", second_class=\"happy\")\nmodel.train_model(epochs=5, model_type=\"s1\", logdir=\"logs\", learning_rate=0.0001, prefetching=True) #, class_weight={0: 1.0, 1: 2.567750677506775})\nmodel.save_model(model_file_name=\"test1\")\n```\n```python\nfrom CustomIntents import BinaryImageClassificator\n\nmodel.load_model(\"models/test1\")\nmodel.realtime_face_prediction()\n```\n\n# PLinearRegression class\n\nit's a simple linear regression class with one input and one output\n\n## Init arguaments\n\n```python\ndef __init__(self, data=None, x_axes1=None, y_axes1=None, model_name=\"test model\"):\n```\n\ndata : if you have your data as a aray like [[x_axes], [y_axes]] you can pass it here\n\nx_axes1 : if you have your x values (inputs) and y values (output) seperetly you can pass the array that contains x valeus here\n\ny_axes1 : if you have your x values (inputs) and y values (output) seperetly you can pass the array that contains y valeus here\n\nmodel_name : name your model\n\n## train model\n\nyou will train your model on your data with this method\n\n```python\ndef train_model(self, algorythm=\"1\", training_steps=10000,\n                start_step=None, verbose=1, plot_input_data=True,\n                learning_rate=0.01, plot_result=True):\n```\n\nalgorythm : you can choose bitween 1, 1.1 and 2  (1 is really simple and fast but 2 is the propper linear reggresion one)\n\ntraining_steps : it's how many steps you want to train your model\n\nstart_step : it's the starting stepfor algorythm 1 and 1.1\n\nverbose : if it's set to 1 it will show you the details of trainong in every step\n\nplot_input_data : it will plot the training data\n\nlearning_rate : it's the learning rate used for algorythm 2\n\nplot_result : it will plot the line of best fit that it found along the side of the training data\n\n## save the model to csv\n\nit will save your model as a csv file containing the information of the line of  best fit\n\n```python\ndef save_model_to_csv(self, file_dir=\"test_model.csv\"):\n```\n\nfile_dir : the name and dir you want to save your model to (include .csv)\n\n## load model from csv\n\nit will load your model from a csv file containing the information of the line of  best fit\n\n```python\ndef load_model_from_csv(self, file_dir=\"test_model.csv\")\n```\n\nfile_dir : the name and dir you want to load your model from (include .csv)\n\n## make prediction\n\nit will make predictions for you\n\n```python\ndef make_prediction(self, x):\n```\n\nx : your input data either in a numerical form or a numpy array containing multiple numerical values\n\nit will return either a float (if you input is just a numerical value) or a numpy array containing multiple floats\n\n# scanner moudule\n\nthis moudule is created for helping you scan faces this is helpful for person recognition emotion recognition etc.\n\n## face_scanner function\n```python\ndef face_scanner(category: str,                  # category name\n                 sub_category: str,              # sub category name\n                 base_dir: str,                  # base directory path\n                 number_of_photos: int,          # number of photos to take\n                 number_of_frames_to_skip: int,  # number of frames to skip before taking images \n                 file_name: str,                 # file name\n                 image_size: int = 256,          # width and height of image (it will be square)\n                 haar_file: str = None,          # directory containing haarcascade\n                 camera: int = 0,                # camera\n                 colored: bool = False):         # True if you want to save the colored image\n```\n\n## facsScannerCliApp\nthis function will command app for facsScanner\n\n```python\nfrom CustomIntents import scanner\n\nscanner.facsScannerCliApp()\n```\n\n## faceScannerGuiApp\nit will command start a GUI app for faceScanner\n\n```python\nfrom CustomIntents import scanner\n\nscanner.faceScannerGuiApp()\n```\n\n\u003ch3\u003eVisitors :\u003c/h3\u003e\n\u003cbr\u003e\n\u003cimg src=\"https://profile-counter.glitch.me/iparsw/count.svg\" alt=\"Visitors\"\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiparsw%2Fcustom-intent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiparsw%2Fcustom-intent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiparsw%2Fcustom-intent/lists"}