This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://www.tensorflow.org/tutorials/distribute/keras | |
| logical_device_names = [logical_device.name for logical_device in tf.config.list_logical_devices()] | |
| if 'GPU' in ''.join(logical_device_names): | |
| distribution_strategy = tf.distribute.MirroredStrategy() | |
| elif 'TPU' in ''.join(logical_device_names): | |
| tf.tpu.experimental.initialize_tpu_system() | |
| tpu = tf.distribute.cluster_resolver.TPUClusterResolver(tpu='/device:TPU_SYSTEM:0') | |
| distribution_strategy = tf.distribute.experimental.TPUStrategy(tpu) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## To setup a project | |
| # Create an empty environment specifying the Python version | |
| conda create --name ml python=3.12 | |
| # Activate the environment | |
| conda activate ml | |
| # Add a new channel | |
| conda config --env --add channels conda-forge | |
| # Install a list of packages | |
| conda install ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| from tensorflow import keras | |
| nn = keras.Sequential(name='CovidClassification') | |
| nn.add(keras.Input(shape=(X_train.shape[1],))) | |
| nn.add(keras.layers.Dense( | |
| units=4, | |
| activation='leaky_relu', | |
| kernel_regularizer=keras.regularizers.L2(), | |
| bias_regularizer=keras.regularizers.L2(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from category_encoders import HashingEncoder | |
| N = unique[column] | |
| encoder = HashingEncoder( | |
| cols=[column], | |
| n_components=math.ceil(math.log2(N)), # the number of bits required to encode N elements | |
| hash_method='sha256' # https://docs.python.org/3/library/hashlib.html#constructors | |
| ) | |
| df = encoder.fit_transform(df) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Splits the values and expands them in multiple numbered columns | |
| temp_df = df[column].str.split("|", expand=True).fillna('') | |
| # One-Hot encodes all the values for each column | |
| temp_df = pd.get_dummies(temp_df).astype('uint8') | |
| # Removes the "N_" prefixe for each column to expose duplicates | |
| temp_df = remove_prefixes(temp_df) | |
| # Merges the duplicate columns |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ffmpeg -hide_banner -i image.jpeg -compression_level 100 out/image.jpeg |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def merge_columns(df: pd.DataFrame) -> pd.DataFrame: | |
| unique_columns = df.columns.unique() | |
| total_n_columns = len(df.columns) | |
| unique_n_columns = len(unique_columns) | |
| print(f"There are {total_n_columns} columns, {unique_n_columns} are unique") | |
| # if there are duplicates at all | |
| if total_n_columns != unique_n_columns: | |
| # get each unique colummn name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| # This method is quite slow for a large number of files (GBs) | |
| # Just wanted to save some parts of the entire snippet for reference | |
| # of some useful stuff like picking a row from a Dask dataframe | |
| # and appending it to a Pandas Dataframe. | |
| for id in unique_ids: | |
| # select all the rows across the partitions for the specified ID | |
| subset = catalogue[catalogue.id == id] | |
| # select only the one row with the latest date and time (max timestamp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <script type="text/javascript"> | |
| // uniformo la chiamata a getUserMedia rispetto ai vari prefissi sperimentali | |
| navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; | |
| // uniformo la chiamata a window.URL sempre rispetto ai prefissi sperimentali | |
| window.URL = window.URL || window.webkitURL; | |
| // invoco la richiesta di accedere sia al flusso video che quello audio, la funzione |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object(box). object(monkey). object(banana). |