How to specify the rembg model - github

I'm using rembg's model to extract images. It uses the default model. However, I want to use Python code to specify other rembg models to extract images
Rembg prompts that rembg - m can be used, but I want to use python code

#import new_session
from rembg.bg import remove, new_session
#create a new session by passing name of the model from one of the following
#["u2net", "u2netp", "u2net_human_seg", "u2net_cloth_seg", "silueta"]
my_session = new_session("u2net_human_seg")
#set session to your custom session
remove(frame, session=my_session)

Related

How can I save the results of different runs in a compare runs experiment in Anylogic?

I want to save the results of different runs in a compare runs experiment in Anylogic in an excel sheet or to some variable or output so that I use these values for some further calculations. How can I do that
Another flexible way of doing this is by writing the results to CSV. This should work for any kind of simulation or experiment with AnyLogic.
You'd have to import standard external libraries into the environment and add code to the experiment to be executed at the end of a simulation run.
Under imports section you could have this:
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.OutputStream;
import java.io.PrintStream;
First create a variable for the filename called csvFileName (you can call it whatever obviously). Then create a function in root called updateMyCSV() or something like that. This function would have a general structure of:
FileWriter pw = new FileWriter(csvFileName, true);
StringBuilder sb;
sb = new StringBuilder();
sb.append(<variablename>); sb.append(',');
Then repeat the above for each variable you want exported
Then finish the function with:
sb.append('\n');
pw.append(sb);
pw.flush();
pw.close();
Best use the build-in database and let it write to Excel at the end of all your runs.
Create a dbase table with columns such as "run_number", "replication_number", "experiment_parameter_X", "my_result_y". Each of your params on Main should get a column (at least those you vary) and each of the output values you are interested in.
This way, you can easily write your model results after each model run using the insertInto command (link).
Finally, just tick the "write to Excel" tickbox in your dbase, select the file and it will write all your raw results.
Also check the example models using the dbase, several use this approach

How to pass values into URL's from csv

DC = Delegate_Code.pop()
print(DC)
with self.client.get("/api/StatusInfo/Get?DelegateCode=KY001"
I want to pass the var 'DC' into the URL (KY001). How is this done? Things I've tried haven't worked.
DC = Delegate_Code.pop()
print(DC)
with self.client.get("/api/StatusInfo/Get?DelegateCode=(DC)"
You can do this in lots of ways (basically any way that python supports)
For example (python 3.6+)
self.client.get(f"/api/StatusInfo/Get?DelegateCode={DC}")
Older:
self.client.get("/api/StatusInfo/Get?DelegateCode=" + DC)
You can also have a look at the csv reader I made specifically for locust (part of locust-plugins). Here's an example of how to use it: https://github.com/SvenskaSpel/locust-plugins/blob/master/examples/csvreader.py

Typo3 Define storagePid for CommandController command

I would like to import different data using a CommandController (scheduler).
I allready figured out that it is possible to set a global storagePid like:
module.tx_myextension.persistence.storagePid = 123
source: https://worksonmymachine.org/blog/commandcontroller-and-storagepid
That works fine, but my extension contains multiple models which should be saved on different Pid's
I also found an old post where someone said it is possible to define a pid for each model which would be exactly what I need:
module.tx_myextension.persistence.classes.tx_myextension_domain_model_player.storagePid = 124
module.tx_myextension.persistence.classes.tx_myextension_domain_model_customer.storagePid = 125
source: https://typo3-german.typo3.narkive.com/WxjjtxXa/scheduler-storage-pid
But it seems like this lines get ignored. Is this the correct way or do I do something wrong?
I am on TYPO3 6.2.44
I suggest to create params for the controller action. For each model a storage pid.
so you have myCommand($domain1Pid, $domain2Pid,$domain3Pid, ...)
Now as first call in your function you get the querySettings for the repositories and apply the storage pids:
$querySettings = $this->domain1Repository->createQuery()->getQuerySettings();
$querySettings->setStoragePageIds([$domain1Pid]);
$this->domain1Repository->setDefaultQuerySettings($querySettings);
repeat this for each repository. In the scheduler job settings or cli you can now define the pids for each storage.
btw: you can also use $domain->setPid(123) to set the pid of each model where to save.

Python w/QT Creator form - Possible to grab multiple values?

I'm surprised to not find a previous question about this, but I did give an honest try before posting.
I've created a ui with Qt Creator which contains quite a few QtWidgets of type QLineEdit, QTextEdit, and QCheckbox. I've used pyuic5 to convert to a .py file for use in a small python app. I've successfully got the form connected and working, but this is my first time using python with forms.
I'm searching to see if there is a built-in function or object that would allow me to pull the ObjectNames and Values of all widgets contained within the GUI form and store them in a dictionary with associated keys:values, because I need to send off the information for post-processing.
I guess something like this would work manually:
...
dict = []
dict['checkboxName1'] = self.checkboxName1.isChecked()
dict['checkboxName2'] = self.checkboxName2.isChecked()
dict['checkboxName3'] = self.checkboxName3.isChecked()
dict['checkboxName4'] = self.checkboxName4.isChecked()
dict['lineEditName1'] = self.lineEditName1.text()
... and on and on
But is there a way to grab all the objects and loop through them, even if each different type (i.e. checkboxes, lineedits, etc) needs to be done separately?
I hope I've explained that clearly.
Thank you.
Finally got it working. Couldn't find a python specific example anywhere, so through trial and error this worked perfectly. I'm including the entire working code of a .py file that can generate a list of all QCheckBox objectNames on a properly referenced form.
I named my form main_form.ui from within Qt Creator. I then converted it into a .py file with pyuic5
pyuic5 main_form.ui -o main_form.py
This is the contents of a sandbox.py file:
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import main_form
# the name of my Qt Creator .ui form converted to main_form.py with pyuic5
# pyuic5 original_form_name_in_creator.ui -o main_form.py
class MainApp(QtWidgets.QMainWindow, main_form.Ui_MainWindow):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
# Push button object on main_form named btn_test
self.btn_test.clicked.connect(self.runTest)
def runTest(self):
# I believe this creates a List of all QCheckBox objects on entire UI page
c = self.findChildren(QtWidgets.QCheckBox)
# This is just to show how to access objectName property as an example
for box in c:
print(box.objectName())
def main():
app = QtWidgets.QApplication(sys.argv) # A new instance of QApplication
form = MainApp() # We set the form to be our ExampleApp (design)
form.show() # Show the form
app.exec_() # and execute the app
if __name__ == '__main__': # if we're running file directly and not importing it
main() # run the main function
See QObject::findChildren()
In C++ the template argument would allow one to specify which type of widget to retrieve, e.g. to just retrieve the QLineEdit objects, but I don't know if or how that is mapped into Python.
Might need to retrieve all types and then switch handling while iterating over the resulting list.

Change name of generated Context file with EF PowerTools Reverse Engineer Code First

I have been attempting to figure out how to make the EF Power Tools - Reverse Engineer Code First use a different name for the generated Context-file, than what it uses now.
Example
I have a database called My_Awesome_Dev_Database. When I run Reverse-engineer against that, the file that is generated will be called:
My_Awesome_Dev_DatabaseContext.cs
What it would like to do is specify what the file is to be called, for instance:
MyAwesomeDatabaseContext.cs
Attempts so far
I have tried looking through the EF.Utilities.CS.ttinclude file, to figure out how the filename is generated - but I have been unsuccessful so far.
Does anyone know ?
Thanks in advance!
Currently the generated context file naming convention is hard-coded and non configurable.
All the logic is inside the ReverseEngineerCodeFirstHandler class (the source is on CodePlex).
It sets the context file name and path with
var contextFilePath = Path.Combine(modelsDirectory,
modelGenerator.EntityContainer.Name + contextHost.FileExtension);
var contextItem = project.AddNewFile(contextFilePath, contextContents);
So the file name is coming from modelGenerator.EntityContainer.Name which gets created upper in the method with:
var contextName =
connection.Database.Replace(" ", string.Empty)
.Replace(".", string.Empty) + "Context";
var modelGenerator =
new EntityModelSchemaGenerator(storeGenerator.EntityContainer,
"DefaultNamespace", contextName);
So as you can see the tool just takes the db name removes the spaces and dots and use it as the context name which will end up as the generated file name.
You can open an issue or - because Entity Framework is open source - take the code, add this configuration option, and send back a pull request.